Understanding CPU time to measure workload

I want to understand the workload of my stored procedures, which run on an instance with many other databases. Among other things I would like to know if I had my own server how many CPU core would I need and how much memory will be enough.

Say I have a server with one core. If I turn on "statistics time" and get 1000 •60•60 = 3600000 ms as CPU time does that mean that the core was occupied 100% for one hour. Is this a valid way to measure e.g. how many cores I need?

How can I measure how much memory is needed for my workload?

Portfolio items created indefinitely from external API. Every time different number

I am trying to make new portfolio item for every json item from external api. I am working on WordPress and placed my code in functions.php of the theme used. When i run my code, it creates portfolio items more than necessary. The items seem to randomly get duplicated even tho i have made validation statement and made sure that each post lug is unique. I want it to stop when the array in json file finishes. Unfortunately I can’t share the api link because it is not supposed to be open-source. It consists of one page. $ model and $ results get correct info. I am new to these WP functions and API thing and got really confused at this point. Hope someone can help me out!:

add_action('wp_ajax_nopriv_get_3dmodels_from_api', 'get_3dmodels_from_api'); add_action('wp_ajax_get_3dmodels_from_api', 'get_3dmodels_from_api');  function get_3dmodels_from_api(){          $  results = wp_remote_retrieve_body(wp_remote_get('<api-url-here>',  array(         'timeout'     => 120,         'httpversion' => '1.1',     ) ) );            $  results = json_decode($  results);     //print_r($  results);           foreach($  results->scenes as $  model) {                  $  model_slug = sanitize_title($  model->name. '-' . $  model->id);                  $  existing_model = get_page_by_path($  model_slug, 'OBJECT', 'portfolio');          if ($  existing_model === null) {              $  inserted_model = wp_insert_post([                 'post_name'=> $  model_slug,                 'post_title'=> $  model_slug,                 'post_type'=> 'portfolio',                 'post_status' => 'publish',             ]);                          if (is_wp_error($  inserted_model)) {                 return false;             }                      $  fillable = [                 'field_605dcef7001bc' => 'name',                 'field_605dcf01001bd' => 'description',                 'field_605dcf09001be' => 'category',                 'field_605dcf13001bf' => 'preview',             ];                          foreach($  fillable as $  key => $  name) {                 $  model_content = $  model->$  name;                                  if ($  name == 'preview') {                     $  model_content = '<img src=' . $  model->$  name . '" alt="">';                 }                                  update_field($  key, $  model_content, $  inserted_model);             }         }  wp_remote_post(admin_url ('admin-ajax.php?action=get_3dmodels_from_api'), [         'blocking' => false,         'sslverify' => false,     ]); } 

Thank you!

Does Gentle Repose extend the time limit for casting Revivify?

The spell revivify returns a creature to life “that has died within the last minute.” [PHB 272]

The spell gentle repose “effectively extends the time limit on raising the target from the dead, since days spent under the influence of this spell don’t count against the time limit of spells such as raise dead.” [PHB 245]

My question is whether revivify is one of the “spells such as raise dead” for which gentle repose “effectively extends the time limit”, taking into account the fact that revivify is two spell levels below raise dead and its default “time limit” is not measured in days (it is in fact 1/1440th of a single day).

How to handle time in D&D 5e

I want to run a campaign where time is a central factor, in the sense that NPCs will be certain places at certain times, and learning these patterns is important, but I’m not sure how to handle it. In combat, I can use the “one turn is 6 seconds” rule, but how do I keep track of time elapsed while my players traipse around the town? While they talk to NPCs?

Does an artificer’s teammate have to re-attune to their infused items every time the infusions change?

Per the artificer rules…

If the item requires attunement, you can attune yourself to it the instant you infuse the item.

Okay. Nice. Great. Except… how does it work when the item is given to another character?

Let’s picture these scenarios: Scenario one. My artificer has created an Resistant Armor, choosing poison. This armor has been given to our paladin, who attuned to it. Now, next long rest, I want to create an Resistant Armor, choosing force. The rules are silent on whether I can attempt to create an infusion I already have existing (as opposed to infusing random other infusions until that one de-infuses) or in fact use the item the previous copy of that infusion is already on. Let’s assume I can.

… but I don’t want to attune to the resulting infusion, so does that mean that, as soon as we finish the long rest, we must immediately do a short rest so the paladin can attune to the armor?

In fact, it doesn’t even end there!

If you try to exceed your maximum number of infusions, the oldest infusion ends, and then the new infusion applies.

Notably, there doesn’t seem to be a process to voluntarily end one of my infusions. Let’s suppose my current infusions are Repeating Weapon, Replicate Magic Item: Alchemy Jug and the aforementioned Resistant Armor: Force. I want to replace the jug with a Mind Sharpener. The only process for this seems to be infusing my chosen item with the Mind Sharpener, causing the Repeating Weapon to end…. then reapply the Repeating Weapon…. which ends the Resistant Armor, requiring me to reapply that, and us to take another short rest to reattune to it!

Is all the above correct, or is there something I’m missing?

Response time optimization – Getting record count based on Input Parameters

I’m trying to optimize the process of calculating count of records, based on variable input parameters. The whole proces spans several queries, functions and stored procedures.

1/ Basically, front-end sends a request to the DB (it calls a Stored procedure) with an input parameter (DataTable). This DataTable (input parameter collection) contains 1 to X records. Each record corresponds to one specific rule.

2/ SP receives the collection of rules (as a custom typed table) and iterates through them one by one. Each rule apart from other meta-data contains a name of a specific function that should be used in evaluating the said rule.

For every rule, the SP prepares a dynamic query wherein it calls the mentioned function with 3 input parameters.

a/ Custom type Memory Optimized Table (Hashed index) b/ collection of lookup values (usually INTs) that the SELECT query uses to filtr data. Ie. "Get me all records, that have fkKey in (x1, x2, x3)" c/ BIT determining if this is the first rule in the whole process.

Each function has an IF statement, that determines based on the c/ parameter if it should return "all" records that fullfill the input criteria (b/). Or if it should fullfill the criteria on top of joining the result of previous rule that is contained in the custom table (a/)

3/ Once the function is run, it’s result is INSERTed into a table variable called @tmpResult. @result is then compared to tmpResult and records that are not in the tmpResult are DELETEd from result.

  • @result is a table variable (custom memory optimized table type), that holds intermediate result during the whole SP execution. It is fully filled up on the first rule, every consequent rule only removes records from it.

4/ The cycle repeats for every rule until all of the rules are done. At the end, count is called on the records in @result and returned as a result of SP.

Few things to take into account:

  • There are dozens of different types of rules. And the list of rules only grows bigger over time. That’s why dynamic query is used.
  • The most effective way to temporarily store records between individual rule execution so far proved to be custom Memory-Optimized table type. We tried a lot of things, but this one seems to be the fastest.
  • The number of records that are usually returned for 1 single rule is roughly somewhere between 100 000 and 3 000 000. That’s why a bucket_size of 5 000 000 for the HASHed temporary tables is used. And even though we tried nonclustered index, it was slower than that HASH.
  • The input collection of rules can vary strongly. There can be anything from 1 rule up to dozens of rules used at once.
  • Most every rules can be defined with at minimum 2 lookup values .. at most with dozens or in a few cases even hundred values. For a better understanding of rules, here are some examples:

Rule1Color, {1, 5, 7, 12} Rule2Size, {100, 200, 300} Rule3Material, {22, 23, 24}

Basically every rule is specified by it’s Designation, which corresponds to a specific Function. And by it’s collection of Lookup values. The possible lookup values differ based on the designation.

What we have done to optimize the process so far:

  • Where big number of records need to be temporarily stored, we use Memory-Optimized variable tables (also tried with temp ones, but it was basically same when using Memory-Optimized variants).
  • We strongly reduced and optimized the source tables the SELECT statements are run against.

Currently, the overal load is somewhat balanced 50/50 between I/O costs pertaining to SELECT statements and manipulation with records between temporary tables. Which is frankly not so good .. ideally the only bottleneck should be the I/O operations, but so far we were not able to come up with a better solution since the whole process has a lot of variability.

I will be happy for any idea you can throw my way. Of course feel free to ask questions if I failed to explain some part of the process adequately.

Thank you

What is the longest possible time a player character can spend preparing their spell list?

Steve is a hypothetical PC with 20 levels in Wizard and an intelligence modifier of +5, and as such he can prepare a total of 25 spells every day. He also has all spells a Wizard could ever learn in this spell book, due to a DM who is really generous in giving out spell scrolls.

One morning he says to himself: "Today I am going to cast something amazing, I just can’t decide what". So he sits down and prepares all possible 9th level spells and as many 8th level spells as he can in addition to that. Resulting in him spending 9 minutes each preparing 16 9th level spells (from the PHB, XGtE and TCoE) and 8 minutes each preparing 9 8th level spells. This results in him spending a total of 216 minutes that morning preparing his spell list.

When it is almost noon, he stumbles out of his room, hungry beyond imagination, down to the dining area of the local tavern, he is currently residing in. He is eager to tell his party members all about his amazing plan and finally eat his first meal of the day. To his astonishment his friends are nowhere to be found. They had waited for him for more than 3 hours, planning their whole adventuring day in the process. They are now on their way to kill that green dragon terrorizing the neighboring kingdom, with or without Steve.

"I made a terrible mistake" Steve mutters to himself. "I didn’t even realize how much time had passed. I must be the worst time-wasting spell preparer in tbe history of the multiverse."

But is he really the one who spend the most possible time imaginable to prepare his spell list or is there any way for a player character to spend more time preparing their spell list then Steve did?