Thanks, @codebien. Full script follows. Note I’m using the “ramp_up” scenario and have been playing with the VU settings to see if reducing them has any affect. To minimize memory requirements, I reduced the preallocated VU’s to 1.
It does seem to be terminating on the file load:
DEBU[0000] Loading... moduleSpecifier="file:///tmp/k6-test-hop-attribution.js" originalModuleSpecifier=k6-test-hop-attribution.js
DEBU[0000] 'k6-test-hop-attribution.js' resolved to 'file:///tmp/k6-test-hop-attribution.js' and successfully loaded 3140 bytes!
DEBU[0000] Gathering k6 runtime options...
DEBU[0000] Initializing k6 runner for 'k6-test-hop-attribution.js' (file:///tmp/k6-test-hop-attribution.js)...
DEBU[0000] Detecting test type for... test_path="file:///tmp/k6-test-hop-attribution.js"
DEBU[0000] Trying to load as a JS test... test_path="file:///tmp/k6-test-hop-attribution.js"
DEBU[0000] Babel: Transformed t=298.848984ms
INFO[0000] Loading hops... source=console
Killed
Code:
import { check, group, sleep } from 'k6';
import http from 'k6/http';
import { Rate } from 'k6/metrics';
import { SharedArray } from 'k6/data';
const filePath = 'replayData/hops.log';
const hopEntries = new SharedArray('hops', function() {
const dataArray = open(filePath).split('\n').filter(ua => ua.trim() !== '');
return dataArray;
});
// Define options for the k6 test
let scenarios = {
normal_usage: {
executor: 'constant-arrival-rate',
startTime: '0s',
gracefulStop: '60s',
duration: '30m',
rate: 1,
timeUnit: '1s',
preAllocatedVUs: 10,
maxVUs: 20
},
ramp_up: {
preAllocatedVUs: 10,
maxVUs: 100,
startRate: 1,
timeUnit: '1s',
executor: 'ramping-arrival-rate',
startTime: '0s',
stages: [
{ target: 1, duration: '1m'},
{ target: 10, duration: '1m'},
{ target: 50, duration: '15m'},
{ target: 100, duration: '15m'},
{ target: 300, duration: '15m' },
{ target: 500, duration: '15m' }
]
}
};
export const options = {
discardResponseBodies: true,
scenarios: {}
}
if (__ENV.scenario) {
// Use just a single scenario if `--env scenario=whatever` is used
options.scenarios[__ENV.scenario] = scenarios[__ENV.scenario];
// Update the start time:
} else {
// Use "normal"
options.scenarios['normal_usage'] = scenarios['normal_usage'];
}
// Define a custom metric to track successful requests
const successfulRequests = new Rate('successful_requests');
// Use `--env mode=debug` (or `-e mode=debug`)
const debug = __ENV.mode && __ENV.mode.toLowerCase() === 'debug';
// Main test function
export default function () {
// Pick a random User-Agent from the list
const randomIndex = Math.floor(Math.random() * hopEntries.length);
const hopEntry = hopEntries[randomIndex].replace(/"/g, '');
if (debug) {
console.log(hopEntry);
}
const fields = hopEntry.split('<!>');
const affiliate = fields[1];
const vendor = fields[2];
const userAgent = fields[3];
const qcookie = fields[4];
const tid = Math.floor(Math.random() * 10000);
const attributionUrl = `https://hop.clickbank-tst.net/?affiliate=${affiliate}&vendor=${vendor}&tid=${tid}`;
const data = {
headers: {
'Content-Type': 'application/json',
'User-Agent': userAgent,
'Referrer': 'https://somereferrer.com?index=' + Math.floor(Math.random() * 100000)
}
};
if (qcookie.length > 0) {
data['headers']['Cookie'] = "q=" + qcookie;
}
// Use `--env debug`
if (debug) {
console.log(attributionUrl);
console.log(data);
}
const res = http.get(attributionUrl, data);
// Check for a successful response
const checkRes = check(res, {
'status is 200': (r) => r.status === 200,
});
// Record the successful request
successfulRequests.add(checkRes);
}
Here are some examples from hops.log:
"1684182619170<!>anhealth<!>livpure<!>""Mozilla/5.0 (iPhone; CPU iPhone OS 16_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 Instagram
282.0.0.17.114 (iPhone11,6; iOS 16_3_1; en_US; en-US; scale=3.00; 1242x2688; 472241688) NW/3<!><!>"
"1684182619141<!>saritatips<!>trabajosoc<!>""Mozilla/5.0 (Linux; Android 12; SM-A042M Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4
.0 Chrome/112.0.5615.135 Mobile Safari/537.36 musical_ly_2022903040 JsSdk/1.0 NetType/WIFI Channel/samsung_store AppName/musical_ly app_version/29.3.4 ByteLocale
/es ByteFullLocale/es Region/AR Spark/1.3.2.2-bugfix AppVersion/29.3.4 BytedanceWebview/d8a21c6<!><!>"