article

Jordan Johnson avatar image
3 Likes"
Jordan Johnson posted

Pulling from Multiple Lists

This article is basically a follow-up to this question:

https://answers.flexsim.com/questions/98195/simultaneous-all-or-nothing-list-pulls.html

In version 22.1, we added a new FlexScript feature called Coroutines. Basically, this lets you wait for events in the middle of executing FlexScript, using the "await" keyword.

Recently, I decided to revisit this question (how to pull from multiple lists at once) and to see if I could use coroutines to simplify the Process Flow.

The short answer is: yes! Here is a model that behaves identically (in terms of which token gets its multi-list request filled first) but replaces about 15 activities with 2 Custom Code blocks:

multipullexample_coroutines_ordering_onfulfill.fsm

In addition to having fewer activities, this model also runs faster (from ~12s to ~2s on my computer).

To determine whether behavior was the same, I added a Statistics Collector and logged request/fullfill times and quantities. I did the same in the original model. The token IDs are off because the older model makes more tokens.

Here's the older version, but with that stats collector, if you want to do your own comparisons.

multipullexample.fsm

The key lines of code are found in the Acquire All activity:

// ~line 47
List.PullResult result = list.pull("", qty, qty, token, partition, flags);
if (result.backOrder) {
    token.Success = 0;
    await result.backOrder;
    return 0;
}
// ...

The new item here is the keyword "await". When the FlexScript execution reaches this line, the FlexScript execution is paused, and waits for the "awaitable" that you specify. In this case, we want to wait for the back order to be fulfilled.

In both models, tokens check all lists to see if they can acquire the complete set of resources. In both models, if a token can't immediately fulfill one of its requests, tokens "go to sleep" until something changes. In the old model, tokens would "wake up" if anything was pushed to the correct list. In contrast, tokens in the new model only "wake up" if enough items are pushed to fulfill their back order. Basically, the second model has fewer false "wakeups" and so runs quite a bit faster.

coroutinesmultipull
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Article

Contributors

jordan.johnson contributed to this article

Related Articles