NewCode CLOUD — 20% off your first month on all cloud VPSClaim

Load Testing Your Hong Kong VPS: k6 and Locust Benchmarking (2026)

· 4 min read

Finding your Hong Kong VPS can only handle 200 concurrent users during a flash sale is expensive. Load testing before you need the capacity tells you exactly where the bottleneck is — database connections, PHP-FPM workers, Nginx upstream timeouts, or raw CPU — and gives you specific numbers to plan infrastructure upgrades.


Step 1: Install k6

<code"># k6 runs from your local machine or a separate "load generator" VPS
# Never run k6 from the same VPS you're testing — it skews results

# macOS
brew install k6

# Linux (load generator)
gpg -k
gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg \
  --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" \
  | tee /etc/apt/sources.list.d/k6.list
apt update && apt install -y k6

Step 2: k6 Test Script

<code"># load-test.js
import http from 'k6/http'
import { check, sleep } from 'k6'
import { Rate, Trend } from 'k6/metrics'

// Custom metrics
const errorRate = new Rate('errors')
const apiLatency = new Trend('api_latency', true)

// Load profile: ramp up, sustain, ramp down
export const options = {
  stages: [
    { duration: '2m', target: 50 },    // Ramp up to 50 VUs over 2 min
    { duration: '5m', target: 50 },    // Hold at 50 VUs for 5 min
    { duration: '2m', target: 200 },   // Spike to 200 VUs
    { duration: '2m', target: 200 },   // Hold the spike
    { duration: '2m', target: 0 },     // Ramp down
  ],
  thresholds: {
    http_req_duration: ['p(95)<500'],   // 95% of requests under 500ms
    http_req_failed: ['rate<0.01'],     // Error rate under 1%
    errors: ['rate<0.05'], }, } const BASE_URL = 'https://yourdomain.com' export default function () { // Test 1: Homepage const home = http.get(`${BASE_URL}/`) check(home, { 'homepage 200': (r) => r.status === 200 })
  apiLatency.add(home.timings.duration)

  // Test 2: API endpoint
  const api = http.get(`${BASE_URL}/api/products?page=1&limit=20`, {
    headers: { 'Authorization': 'Bearer TEST_TOKEN' },
  })
  check(api, {
    'api 200': (r) => r.status === 200,
    'api has data': (r) => JSON.parse(r.body).data?.length > 0,
  })
  errorRate.add(api.status !== 200)

  // Test 3: POST (simulate checkout)
  const checkout = http.post(
    `${BASE_URL}/api/orders`,
    JSON.stringify({ product_id: 1, quantity: 1 }),
    { headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer TEST_TOKEN' } }
  )
  check(checkout, { 'checkout 201': (r) => r.status === 201 })

  sleep(Math.random() * 2 + 1)  // Random 1-3 second think time
}

Step 3: Run and Interpret Results

<code"># Run from a Singapore or Japan VPS (simulate Asia-Pacific users)
k6 run --out json=results.json load-test.js

# Output:
#          ✓ homepage 200
#          ✓ api 200
#          ✗ checkout 201 ← FAILURES HERE
#
# http_req_duration............: avg=245ms p(90)=890ms p(95)=1.2s p(99)=3.4s
# http_req_failed..............: 2.1%  ← Above 1% threshold — FAIL

# Diagnose while test runs (on the HK VPS):
watch -n 2 'uptime; free -h; ss -s'   # CPU load, RAM, connections
tail -f /var/log/nginx/error.log       # Nginx errors
sudo -u postgres psql -c "SELECT count(*), state FROM pg_stat_activity GROUP BY state;"
# active: 10  idle: 5  idle in transaction: 50 ← connection leak!

Step 4: Locust for Python Applications

<code"># pip install locust

# locustfile.py
from locust import HttpUser, task, between, constant_throughput

class APIUser(HttpUser):
    wait_time = between(1, 3)  # 1-3 seconds between requests

    def on_start(self):
        """Login once per user session"""
        resp = self.client.post('/api/auth/login', json={
            'email': 'test@example.com',
            'password': 'testpassword'
        })
        self.token = resp.json().get('token')
        self.headers = {'Authorization': f'Bearer {self.token}'}

    @task(5)  # Weight 5 — 5× more common than checkout
    def browse_products(self):
        self.client.get('/api/products', headers=self.headers)

    @task(2)
    def view_product(self):
        self.client.get('/api/products/1', headers=self.headers)

    @task(1)
    def add_to_cart(self):
        self.client.post('/api/cart', json={'product_id': 1}, headers=self.headers)

# Run Locust web UI:
locust -f locustfile.py --host=https://yourdomain.com
# Open http://localhost:8089 → set users=200, spawn rate=10

Step 5: Identify Common Bottlenecks

Symptom Bottleneck Fix
CPU 100%, slow responses PHP/Python processing More PHP-FPM workers, add PM2 cluster instances
“upstream timed out” in Nginx logs App workers exhausted Increase pm.max_children, add worker instances
DB “too many connections” error Connection pool exhausted Add PgBouncer, reduce pool size per worker
p99 latency spikes but avg is low GC pauses or slow queries Tune JVM GC, add database indexes
Errors only above 100 VU File descriptor limit ulimit -n 65536 in systemd unit
RAM OOM, process restarts Memory leak or undersized Fix leak or add swap as buffer, upgrade plan

Step 6: Capacity Planning

<code"># After load testing, calculate your capacity headroom:
# If at 100 VU: CPU = 60%, p95 latency = 300ms
# At 200 VU:   CPU = 85%, p95 latency = 800ms
# At 250 VU:   CPU = 95%, p95 = 2000ms, errors start

# Current capacity: ~200 concurrent users before degradation
# Safe operating point: 70% of capacity = 140 concurrent users

# If peak traffic = 500 concurrent → need 3-4× current resources
# Options: upgrade VPS (4 GB → 8 GB), add horizontal load-balanced VPS,
#          or optimise identified bottleneck (usually faster/cheaper)

Conclusion

Load testing your Hong Kong VPS application before traffic peaks turns guesswork into data — k6 and Locust generate realistic load patterns from Asia-Pacific locations, expose the exact bottleneck (database connections, worker processes, or memory), and give you specific thresholds to monitor in production. Running tests from Singapore or Tokyo simulates real CN2 GIA-routed traffic patterns your users experience, making the benchmarks meaningful for capacity planning.

Test before it matters: Browse Server.HK Hong Kong VPS plans — provision a separate small VPS as a load generator, or run k6 from a cloud VM to test your production HK VPS under realistic Asia-Pacific load.

Related articles

More in VPS & ServersServer setup guides