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 and routes all http.get/post calls through the proxy.
Run separate k6 instances with different HTTP_PROXY usernames (USER-country-us, USER-country-jp, etc.) to simulate multi-region load.
Yes. http_req_duration will include proxy latency. Account for this in your thresholds or subtract the baseline proxy RTT.
k6 supports SOCKS5 via the ALL_PROXY env var. Set ALL_PROXY=socks5://USER:PASS@gw.knoxproxy.com:7001 for SOCKS5 routing.
Free trial on rotating residential -- 5 minutes setup, no credit card.