K6 extension for TCP connections with bandwidth throttling and ACK delay control.
- TCP connection with receive buffer control
- Bandwidth throttling (bytes per second)
- ACK delay simulation for natural bandwidth throttling
- Compatible with K6 load testing
xk6 build --with github.com/skyloud/xk6-tcp-throttlingimport tcpThrottle from 'k6/x/tcp-throttling';
export default function() {
const conn = tcpThrottle.connect('server:80');
// Method 1: Bandwidth throttling (1MB/s)
conn.setBandwidthLimit(1024 * 1000);
const data1 = conn.readWithThrottle(8192);
// Method 2: ACK delay simulation
const data2 = conn.readWithDelay(8192, 100);
// Method 3: TCP window control
conn.setReceiveBuffer(1024);
conn.close();
}connect(addr)- Create TCP connectionsetBandwidthLimit(bytesPerSecond)- Set bandwidth limitreadWithThrottle(size)- Read with automatic bandwidth throttlingsetReceiveBuffer(size)- Set SO_RCVBUF socket optionreadWithDelay(size, delayMs)- Read data with ACK delaywrite(data)- Write dataclose()- Close connection
Bandwidth throttling implementation inspired by go-throttle