k6 is an open-source load testing tool by Grafana Labs that uses JavaScript ES6 scripts. Route k6 traffic through KnoxProxy to simulate load from multiple geographic regions, test CDN edge behavior, and stress-test APIs through rotating residential IPs.
Install k6 on your system.
brew install k6
# or download from https://k6.io/docs/get-started/installation/k6 respects the HTTP_PROXY and HTTPS_PROXY environment variables for routing all requests through a proxy.
export HTTP_PROXY=http://USER:PASS@gw.knoxproxy.com:7000
export HTTPS_PROXY=http://USER:PASS@gw.knoxproxy.com:7000Create a k6 script that sends requests through the proxy.
import http from 'k6/http';
import { check } from 'k6';
export const options = {
vus: 10,
duration: '30s',
};
export default function () {
const res = http.get('https://httpbin.org/ip');
check(res, { 'status 200': (r) => r.status === 200 });
}Change the proxy username to simulate traffic from a specific country.
export HTTP_PROXY=http://USER-country-de:PASS@gw.knoxproxy.com:7000
k6 run load-test.jsUse session IDs in the proxy username to maintain the same IP across a virtual user lifecycle.
export HTTP_PROXY=http://USER-session-vu${__VU}:PASS@gw.knoxproxy.com:7000Execute the load test with proxy routing active.
HTTP_PROXY=http://USER:PASS@gw.knoxproxy.com:7000 \
HTTPS_PROXY=http://USER:PASS@gw.knoxproxy.com:7000 \
k6 run load-test.jsimport http from 'k6/http';
import { check, sleep } from 'k6';
import { Rate } from 'k6/metrics';
const errorRate = new Rate('errors');
export const options = {
stages: [
{ duration: '30s', target: 20 },
{ duration: '1m', target: 50 },
{ duration: '30s', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<3000'],
errors: ['rate<0.1'],
},
};
export default function () {
// All requests route through KnoxProxy via HTTP_PROXY env
const res = http.get('https://httpbin.org/ip');
const success = check(res, {
'status is 200': (r) => r.status === 200,
'has origin IP': (r) => JSON.parse(r.body).origin !== undefined,
});
errorRate.add(!success);
sleep(1);
}k6 creates new connections per virtual user. Each VU gets a different IP through the rotating proxy by default. For sticky IPs per VU, use USER-session-vu{id} in the proxy username.
| Problem | Fix |
|---|---|
| WARN request failed: proxyconnect tcp: dial tcp: lookup gw.knoxproxy.com | Verify DNS resolution: nslookup gw.knoxproxy.com. Check network connectivity. |
| request failed: 407 Proxy Authentication Required | Ensure HTTP_PROXY includes USER:PASS in the URL. URL-encode special characters in the password. |
| High p95 latency through proxy | Adjust thresholds to account for proxy latency. Use a proxy region closer to the target server. |
USER-country-de-city-berlin-session-profile07Order matters -- geo flags before the session flag. The session name is free text; use the profile ID so the mapping is self-documenting. Password stays as issued; no flags belong there. HTTP on :7000, SOCKS5 on :7001, same credentials.
Yes, k6 reads the standard HTTP_PROXY and HTTPS_PROXY environment variables at startup and routes every http.get and http.post call in your script through that proxy automatically. No script changes are needed beyond exporting the variables before running k6 run, and the same variables also support country-targeted usernames.
Yes, run separate k6 instances, each with a different HTTP_PROXY username such as USER-country-us or USER-country-jp, to simulate load originating from multiple regions at the same time. Combine this with the staged options.stages ramp-up pattern in each instance to build a realistic multi-country load profile.
Yes, the http_req_duration metric will include the extra network hop through KnoxProxy, so raw latency numbers run slightly higher than a direct connection would show. Account for this in your p(95) thresholds, or measure the baseline proxy round-trip time separately and subtract it before comparing results across test runs.
Yes, k6 supports SOCKS5 through the ALL_PROXY environment variable rather than the HTTP_PROXY variable used for regular HTTP proxying. Set ALL_PROXY=socks5://USER:PASS@gw.knoxproxy.com:7001 before running k6 run, and every http.get and http.post call in the script routes through the SOCKS5 endpoint on port 7001 instead.
Rotating residential proxies -- 5 minutes setup, instant activation, 14-day money-back guarantee.