@artilleryio/int-core 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/engine_http.js +7 -0
- package/lib/phases.js +32 -14
- package/lib/runner.js +2 -1
- package/package.json +1 -1
package/lib/engine_http.js
CHANGED
|
@@ -656,6 +656,7 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
656
656
|
requestParams.retry = 0; // disable retries - ignored when using streams
|
|
657
657
|
|
|
658
658
|
const uuid = crypto.randomUUID();
|
|
659
|
+
let totalDownloaded = 0;
|
|
659
660
|
request(requestParams)
|
|
660
661
|
.on('request', function (req) {
|
|
661
662
|
ee.emit('trace:http:request', requestParams, uuid);
|
|
@@ -664,6 +665,9 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
664
665
|
ee.emit('counter', 'http.requests', 1);
|
|
665
666
|
ee.emit('rate', 'http.request_rate');
|
|
666
667
|
req.on('response', function (res) {
|
|
668
|
+
res.on('end', () => {
|
|
669
|
+
ee.emit('counter', 'http.downloaded_bytes', totalDownloaded);
|
|
670
|
+
});
|
|
667
671
|
ee.emit('trace:http:response', res, uuid);
|
|
668
672
|
self._handleResponse(
|
|
669
673
|
requestParams,
|
|
@@ -676,6 +680,9 @@ HttpEngine.prototype.step = function step(requestSpec, ee, opts) {
|
|
|
676
680
|
});
|
|
677
681
|
|
|
678
682
|
})
|
|
683
|
+
.on('downloadProgress', (progress) => {
|
|
684
|
+
totalDownloaded = progress.total;
|
|
685
|
+
})
|
|
679
686
|
.on('error', function (err, body, res) {
|
|
680
687
|
ee.emit('trace:http:error', err, uuid);
|
|
681
688
|
if (err.name === 'HTTPError') {
|
package/lib/phases.js
CHANGED
|
@@ -107,14 +107,20 @@ function createRamp(spec, ee) {
|
|
|
107
107
|
|
|
108
108
|
const difference = rampTo - arrivalRate;
|
|
109
109
|
const periods = duration;
|
|
110
|
-
debug(
|
|
110
|
+
debug(
|
|
111
|
+
`worker ${worker} totalWorkers ${totalWorkers} arrivalRate ${arrivalRate} rampTo ${rampTo} difference ${difference} periods ${periods}`
|
|
112
|
+
);
|
|
111
113
|
|
|
112
114
|
const periodArrivals = [];
|
|
113
115
|
const periodTick = [];
|
|
114
116
|
// if there is only one peridod we generate mean arrivals
|
|
115
117
|
if (periods === 1) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
const rawPeriodArrivals = (rampTo + arrivalRate) / 2;
|
|
119
|
+
periodArrivals[0] = adjustArrivalsByWorker(
|
|
120
|
+
rawPeriodArrivals,
|
|
121
|
+
totalWorkers,
|
|
122
|
+
worker
|
|
123
|
+
);
|
|
118
124
|
} else {
|
|
119
125
|
// for each period we calculate the corresponding arrivals:
|
|
120
126
|
// knowing that arrivals(0) = arrivalRate and arrivals(duration -1) = rampTo
|
|
@@ -122,18 +128,15 @@ function createRamp(spec, ee) {
|
|
|
122
128
|
for (let i = 0; i < periods; i++) {
|
|
123
129
|
const rawPeriodArrivals = (difference / (duration - 1)) * i + arrivalRate;
|
|
124
130
|
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (Math.round((rawPeriodArrivals % 1) * totalWorkers) >= worker) {
|
|
132
|
-
periodArrivals[i] = periodArrivals[i] + 1;
|
|
133
|
-
}
|
|
131
|
+
// take into account added decimals and bump worker arrivals if needed
|
|
132
|
+
periodArrivals[i] = adjustArrivalsByWorker(
|
|
133
|
+
rawPeriodArrivals,
|
|
134
|
+
totalWorkers,
|
|
135
|
+
worker
|
|
136
|
+
);
|
|
134
137
|
|
|
135
138
|
// Needed ticks to get to periodArrivals in 1000ms
|
|
136
|
-
periodTick[i] =
|
|
139
|
+
periodTick[i] = Math.min(Math.floor(1000 / periodArrivals[i]), 1000);
|
|
137
140
|
}
|
|
138
141
|
}
|
|
139
142
|
|
|
@@ -148,9 +151,24 @@ function createRamp(spec, ee) {
|
|
|
148
151
|
}
|
|
149
152
|
|
|
150
153
|
ee.emit('phaseCompleted', spec);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
function adjustArrivalsByWorker(rawPeriodArrivals, totalWorkers, worker) {
|
|
157
|
+
// We use the floor of the expected arrivals, then we add up all decimal digits
|
|
158
|
+
// and evaluate if one or more workers should bump their arrivalRate.
|
|
159
|
+
let arrivals = Math.floor(rawPeriodArrivals);
|
|
160
|
+
|
|
161
|
+
// Think of fractionalPart * workers as the amount of arrivals that could not be
|
|
162
|
+
// shared evenly across all workers.
|
|
163
|
+
if (Math.round((rawPeriodArrivals % 1) * totalWorkers) >= worker) {
|
|
164
|
+
arrivals = arrivals + 1;
|
|
165
|
+
}
|
|
166
|
+
return arrivals;
|
|
151
167
|
}
|
|
152
168
|
|
|
153
169
|
function ticker(currentPeriod) {
|
|
170
|
+
// ensure we don't go past 1s
|
|
171
|
+
const delay = Math.min(periodTick[currentPeriod], 1000);
|
|
154
172
|
let currentArrivals = 0;
|
|
155
173
|
let arrivalTimer = driftless.setDriftlessInterval(function arrivals() {
|
|
156
174
|
if (currentArrivals < periodArrivals[currentPeriod]) {
|
|
@@ -160,7 +178,7 @@ function createRamp(spec, ee) {
|
|
|
160
178
|
currentPeriod++;
|
|
161
179
|
driftless.clearDriftless(arrivalTimer);
|
|
162
180
|
}
|
|
163
|
-
},
|
|
181
|
+
}, delay);
|
|
164
182
|
return;
|
|
165
183
|
}
|
|
166
184
|
}
|
package/lib/runner.js
CHANGED
|
@@ -386,7 +386,8 @@ function createContext(script, contextVars) {
|
|
|
386
386
|
{
|
|
387
387
|
target: script.config.target,
|
|
388
388
|
$environment: script._environment,
|
|
389
|
-
$processEnvironment: process.env
|
|
389
|
+
$processEnvironment: process.env, // TODO: deprecate
|
|
390
|
+
$env: process.env,
|
|
390
391
|
},
|
|
391
392
|
contextVars || {}
|
|
392
393
|
),
|