Repository navigation
Exposing a per-worker ordinal to processor code #3759
bts-bastion
started this conversation in
Artillery
Replies: 1 comment
|
Following up on this: we've implemented it on our fork and use it in our own load testing.
Branch: https://github.com/bastionplatforms/artillery/tree/feat/worker-ordinal-env Would you be open to this as a contribution? If so, what's the best way to get it to you? |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
The problem
Some load tests need each worker to own a disjoint slice of shared data — a cohort of
pre-provisioned identities, a pool of accounts that can't be used concurrently, a
partition of a seed dataset. Processor code can't currently answer "which worker am I,
out of how many?", so there's no way to compute a slice without external coordination.
Two existing threads touch on this:
The ordinal already exists internally
packages/artillery/lib/dist.ts, after idle-only workers are filtered out:and it immediately uses that ordinal to give each worker every Nth row of
config.payload:So the ordinal is already computed, already dense, and already relied on by
own payload distribution. It just isn't reachable from processor code —
phase.workerisread only by the phaser, and the only worker identity on the environment is
LOCAL_WORKER_ID, which is the rawthreadId: opaque rather than a 0-based ordinal, andnot unique across nodes.
Two gaps follow from it being internal:
config.payloadCSVs, not for data aprocessor loads or generates itself.
artillery runover the fulldataset and divides it among its own threads, so node A's worker 0 and node B's
worker 0 get identical rows.
Proposal
ARTILLERY_WORKER_INDEXARTILLERY_WORKER_COUNTThe
ARTILLERY_WORKER_*prefix follows the existingARTILLERY_WORKER_PLATFORM.Scope of the change
Nothing inside Artillery reads these variables, so they can't affect arrival rates, VU
counts, phases or worker allocation — the values are reported, not acted on. No new state
is computed either; these are
divideWork's existing numbers, so there's no secondmechanism to keep in sync.
The local change is 49 added lines (13 of code, the rest licence header and
with no deletions and no new dependencies: one import and one call site in
platform/local/worker.ts, plus a new file. Absent phases, absent annotations,--solo,or a single-worker machine all yield index
0/ count1, which is correct for aone-worker run rather than a special case.
For distributed runs the launcher merges a few keys into the per-invocation
event.ENVit already sends. The stock Lambda handler forwards
event.ENVinto the childartillery run, so no worker-image change is needed. The launcher communicates viaARTILLERY_WORKER_BASEandARTILLERY_WORKER_COUNT;ARTILLERY_WORKER_INDEXis alwaysderived, so a pre-set value of that name would be overwritten.
The part I'm least sure about
Distributed runs are two-layered. Since
--solois opt-in, by default eachfull
artillery runthat uses the local platform internally, so the processor executes ina nested worker thread with
M = cpus() - 1threads per node. One ordinal per nodetherefore isn't unique at the granularity that generates load; the node index has to be
composed with the nested local index:
The launcher doesn't reliably know each node's runtime
M, so the stride has to come fromsomewhere. The strawman is a user-supplied
ARTILLERY_WORKERS_PER_NODE(default1; setto
vCPUs - 1, or left at1under--solo). A stride larger than the real thread countis safe — it leaves gaps, never overlaps — but a smaller one overlaps, which is a footgun lying
in wait.
I'm not attached to that approach. Alternatives: each node reports its actual thread count
and the launcher assigns ranges;
--solobecomes the default for distributed runs so thestride is always
1; or the stride is derived from the vCPU count implied by theconfigured Lambda memory or ECS task size. The local case has no stride question at all,
which may make it a more sensible first step than local + Lambda together.
On Redis
Redis is the recommendation in #3597 and it's the right tool when workers need to consume
from a shared queue. It's a heavier fit when the split is statically computable — an
external service to provision and tear down, a round trip per VU, and it rules out
VPC-restricted or air-gapped runs. That's the case I think an ordinal covers rather than
competes with.
Questions
coordination the intended answer for this class of problem?
ARTILLERY_WORKER_INDEX/ARTILLERY_WORKER_COUNTthe right0-based as proposed or 1-based to match
phase.worker, and env vars or context vars(
$workerIndex/$workerCount)? Env works at processor module scope and crosses thenested-process boundary without new plumbing; context vars read better in YAML.
The local half is implemented with unit and integration coverage — ordinals observed
across N workers are exactly
{0..N-1}, each once. Happy to open a PR if this is adirection you'd take.
All reactions