Complete Bottleneck Analysis in Load Testing

Our company is engaged in the development, support and maintenance of sites of any complexity. From simple one-page sites to large-scale cluster systems built on micro services. Experience of developers is confirmed by certificates from vendors.

Development and maintenance of all types of websites:

Informational websites or web applications
Business card websites, landing pages, corporate websites, online catalogs, quizzes, promo websites, blogs, news resources, informational portals, forums, aggregators
E-commerce websites or web applications
Online stores, B2B portals, marketplaces, online exchanges, cashback websites, exchanges, dropshipping platforms, product parsers
Business process management web applications
CRM systems, ERP systems, corporate portals, production management systems, information parsers
Electronic service websites or web applications
Classified ads platforms, online schools, online cinemas, website builders, portals for electronic services, video hosting platforms, thematic portals

These are just some of the technical types of websites we work with, and each of them can have its own specific features and functionality, as well as be customized to meet the specific needs and goals of the client.

Showing 1 of 1All 2062 services
Complete Bottleneck Analysis in Load Testing
Medium
~2-3 days
Frequently Asked Questions

Our competencies:

Development stages

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1358
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1250
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    956
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1188
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    929
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    947

How to Systematically Identify a Performance Bottleneck

Your load test shows degradation: latency jumps from 50 ms to 2000 ms, and the logs are silent. This comprehensive bottleneck analysis reveals root causes. Our performance analysis has been trusted by enterprise clients for over a decade. In one case, the cause was a slow JSON.parse in a hot path — replacing it with simdjson reduced p95 latency from 200 ms to 30 ms (a 85% reduction), and infrastructure costs dropped by over 60% (saving $7,000 per month). The approach is straightforward: measure → find → eliminate → repeat.

Diagnostic Framework: From Metrics to Bottleneck

First, look at top-level metrics. If p95 latency is high but CPU is below 70%, suspect the database or external calls. If CPU is 90–100%, profile the code. If memory grows and swap is active, look for a leak. System errors (ENOMEM, EMFILE) indicate OS limits. 502/504 errors — check the load balancer.

High latency or errors
        │
        ├── p95 latency high, CPU < 70%, memory OK
        │   └── → Database: slow queries, locks, N+1
        │
        ├── CPU 90–100%, latency grows proportionally
        │   └── → Compute bottleneck: profile CPU-hot paths
        │
        ├── Memory grows, swap active
        │   └── → Memory leak or heap too small
        │
        ├── ENOMEM / EMFILE / ECONNREFUSED
        │   └── → System limits: ulimit, file descriptors, TCP backlog
        │
        └── Errors 502/504, app OK
            └── → Nginx upstream, load balancer timeout

Database Optimization: Slow Queries and N+1

How to Find Slow Queries in PostgreSQL?

Run these queries during the load test. The first shows active queries with duration. The second — locks (who is waiting for whom). The third — heaviest queries by total time. The fourth — tables with sequential scans (potential missing indexes). For more details, see the PostgreSQL Documentation on pg_stat_statements.

-- Running queries right now (run during the test)
SELECT pid, now() - query_start AS duration,
       state, wait_event_type, wait_event,
       left(query, 100) AS query_preview
FROM pg_stat_activity
WHERE state != 'idle'
  AND query NOT LIKE '%pg_stat_activity%'
ORDER BY duration DESC;

-- Locks: who blocks whom
SELECT blocked.pid, blocked.query,
       blocking.pid AS blocking_pid,
       blocking.query AS blocking_query
FROM pg_stat_activity blocked
JOIN pg_stat_activity blocking
  ON blocking.pid = ANY(pg_blocking_pids(blocked.pid))
WHERE cardinality(pg_blocking_pids(blocked.pid)) > 0;

-- Heaviest queries (pg_stat_statements)
SELECT query, calls, mean_exec_time, total_exec_time,
       stddev_exec_time, rows
FROM pg_stat_statements
ORDER BY total_exec_time DESC
LIMIT 20;

-- Missing indexes: sequential scans on large tables
SELECT relname, seq_scan, seq_tup_read,
       idx_scan, seq_tup_read / nullif(seq_scan, 0) AS avg_rows_per_seqscan
FROM pg_stat_user_tables
WHERE seq_scan > 100
  AND seq_tup_read > 10000
ORDER BY seq_tup_read DESC;

Why N+1 Queries Are a Common Cause of Degradation?

N+1 occurs when an ORM issues a separate query for each parent object to fetch related data. With 1000 users, that's 1001 queries instead of a single JOIN. Symptoms: the number of active connections to the database equals the number of virtual users, and pg_stat_statements shows the same query with a large number of calls. Solution: eager loading, DataLoader, or manual JOIN. We specialize in N+1 query elimination. Using pg_stat_statements to detect N+1 is 10 times faster than manual log analysis.

Application Profiling: Node.js, Python, and Connection Pool

CPU Profiling in Node.js

The simplest method is to enable the V8 profiler via a signal. Run the code under load, send kill -USR1 <pid>, after 30 seconds get cpu-profile.cpuprofile, open in Chrome DevTools.

// server.js — enable V8 profiling via signal
process.on('SIGUSR1', () => {
  const { Session } = require('inspector')
  const session = new Session()
  session.connect()

  session.post('Profiler.enable')
  session.post('Profiler.start')

  // Profile for 30 seconds
  setTimeout(() => {
    session.post('Profiler.stop', (err, { profile }) => {
      require('fs').writeFileSync('./cpu-profile.cpuprofile', JSON.stringify(profile))
      console.log('CPU profile saved to cpu-profile.cpuprofile')
      session.disconnect()
    })
  }, 30000)
})

// Run under load: kill -USR1 <pid>
// Open in Chrome DevTools → More Tools → JavaScript Profiler

An alternative is to use the 0x utility to generate a flamegraph. It collects stack traces and renders an interactive graph where bar width represents execution time. Typical findings: JSON.parse/stringify in hot paths, bcrypt with high cost factor, uncached regex, synchronous file operations.

npm install -g 0x
0x --output-dir profile node server.js &
APP_PID=$!
k6 run tests/load/main.js
kill -USR2 $APP_PID
# Opens flamegraph.html

Python Profiling Under Load

For production we use pyinstrument — it doesn't require restart and gives a detailed report per request. Add middleware that enables profiling via ?profile=true.

from pyinstrument import Profiler
from flask import request, g

@app.before_request
def start_profiler():
    if request.args.get('profile') == 'true':
        g.profiler = Profiler()
        g.profiler.start()

@app.after_request
def stop_profiler(response):
    if hasattr(g, 'profiler'):
        g.profiler.stop()
        response.data = g.profiler.output_html()
        response.content_type = 'text/html'
    return response

# Request with profiling: GET /api/posts?profile=true

Connection Pool Analysis

If clients are waiting for a connection (cl_waiting > 0 in pgBouncer), the pool is too small. Check via SHOW POOLS; or SQL query to pg_stat_activity.

-- PostgreSQL: connection pool statistics
SELECT datname, count(*) AS total_connections,
       count(*) FILTER (WHERE state = 'active') AS active,
       count(*) FILTER (WHERE state = 'idle') AS idle,
       count(*) FILTER (WHERE wait_event_type = 'Lock') AS waiting_lock
FROM pg_stat_activity
GROUP BY datname;

k6 Time-Series Analysis: How to Find the Degradation Point?

The script analyzes the p95 latency time series and finds the first minute when the value exceeded a threshold (e.g., 500 ms). This helps pinpoint the degradation to a specific test moment.

Script for k6 time-series analysis (click to expand)
import json
import pandas as pd

def find_degradation_point(json_results: str):
    """Find the degradation point from metric time series"""
    records = []
    with open(json_results) as f:
        for line in f:
            try:
                record = json.loads(line)
                if record.get('type') == 'Point':
                    records.append({
                        'timestamp': record['data']['time'],
                        'metric': record['metric'],
                        'value': record['data']['value']
                    })
            except:
                continue
    df = pd.DataFrame(records)
    df['timestamp'] = pd.to_datetime(df['timestamp'])
    p95_df = df[df['metric'] == 'http_req_duration'].copy()
    p95_df = p95_df.set_index('timestamp').resample('1min')['value'].quantile(0.95)
    threshold = 500
    degradation = p95_df[p95_df > threshold]
    if not degradation.empty:
        print(f"Degradation detected at: {degradation.index[0]}")
        print(f"p95 at degradation: {degradation.iloc[0]:.0f}ms")
    else:
        print("No degradation detected (all within threshold)")
    return p95_df

Tools and Typical Optimizations

Profiling Tools Comparison

Tool Scope Depth Production Impact
pg_stat_statements PostgreSQL High None
V8 profiler Node.js High Minimal
pyinstrument Python Medium None
0x Node.js High Requires restart
flamegraph General High Depends on collector

Typical Optimizations After Analysis

Bottleneck Symptom Solution
N+1 queries to DB DB active queries >> VU count DataLoader / eager loading / JOIN
Missing index SeqScan on large table CREATE INDEX CONCURRENTLY
Slow JSON serialization CPU high, hot path in serialize Protobuf / simdjson / msgpack
Connection pool overflow cl_waiting > 0 in pgBouncer Increase pool_size or add replicas
GC pauses Spiky latency without CPU load Increase heap, tune GC flags
Table locks wait_event = Lock in pg_stat Optimize operation order, NOWAIT

Analysis Results and Order Process

After the analysis, we deliver:

  • Report with time-series graphs (latency, throughput, CPU, memory, database metrics)
  • Scripts to reproduce the load
  • Detailed list of bottlenecks with code and configuration snippets
  • Optimization recommendations (priority, effort estimates)
  • Verification test after changes are applied
  • Architecture consultation to prevent future issues

What’s Included in the Analysis

Our comprehensive package includes:

  • Detailed documentation of findings
  • Access to load testing scripts and profiling tools
  • Training session for your team on bottleneck identification
  • 30 days of email support for questions on optimizations

A full analysis with report and verification takes 1–2 business days. Pricing is customized based on system complexity. Contact us — we'll evaluate your project and recommend the optimal engagement. Our engineers have 10+ years of experience in load testing and optimization. Average cloud cost savings after our optimizations range from $3,000 to $10,000 per month.

Why are unit tests important but not a panacea?

A bug found by a unit test costs minutes to fix. The same bug in production costs hours of incident response, compensations, and lost trust. In an online store project, a discount calculation error passed manual testing, went to production, and processed 37 orders at zero price in 4 hours. An automated test for edge cases would have caught it on the first push. With 7+ years in web application testing and over 200 projects delivered, we’ve seen this pattern repeat across industries.

Jest is the standard for JavaScript/TypeScript, but unit tests are justified only where there is isolated logic: transformation functions, validators, business rules, utilities. Testing React components with Jest + Testing Library is correct for behavioral tests: "button appears after loading", "form shows error on empty email". Snapshot tests (toMatchSnapshot) are a trap: they break on any layout change and become noise that developers update without looking. Code coverage is a poor quality metric: 80% coverage can be achieved with tests that check nothing. Coverage shows that code executed, not that it works correctly.

Criteria Jest Vitest
Speed for large projects Medium (Babel transformation) 10–20x faster (ES modules)
Integration with Vite Via plugin Native
Monorepos Requires configuration Out of the box

Vitest as an alternative to Jest for Vite projects: 10–20x faster due to native ES modules without Babel transformation. For monorepos with thousands of tests, the speed difference is noticeable. Wikipedia on unit testing describes the theoretical foundation — we apply it with real CI pipelines.

How to set up E2E tests that are not flaky?

Playwright outperforms Cypress on key parameters: native multi-tab, multi-origin, iframe support; parallel execution at test level; WebKit, Firefox, Chromium out of the box; no iframe for the app — tests run in a real browser.

Playwright codegen records actions and generates a test — a good starting point, but generated code needs refactoring. Locators by text content are fragile: getByRole('button', { name: 'Place order' }) is more robust than locator('.btn-primary').

Page Object Model is the standard for organizing E2E tests. Each page is a separate class with methods instead of direct locators. When a button moves from header to sidebar — change in one place, not across all tests.

Flaky tests typically arise from race conditions between request and render, animations without wait, and dependency on external APIs. Solution: page.waitForResponse() instead of page.waitForTimeout(), mocking external APIs via page.route().

// Bad
await page.click('#submit');
await page.waitForTimeout(2000);
await expect(page.locator('.success')).toBeVisible();

// Good
await page.click('#submit');
await page.waitForResponse(resp =>
  resp.url().includes('/api/orders') && resp.status() === 201
);
await expect(page.getByRole('alert', { name: /order created/i })).toBeVisible();

Our engineers guarantee test stability in CI. Playwright’s official documentation covers all API details — we use it daily on projects with millions of users.

How do Core Web Vitals affect ranking?

Google uses Core Web Vitals in ranking. Lighthouse CLI in CI pipeline: on every deploy we check that LCP < 2.5s, CLS < 0.1, INP < 200ms. Google Chrome study: 53% of users leave a site if it takes longer than 3 seconds to load — our tests prevent such losses.

Real problems that Lighthouse finds:

  • Hero image without width/height attributes: CLS 0.35 on load.
  • JavaScript bundle 2.1MB synchronously blocking parsing: INP 450ms.
  • Fonts without font-display: swap: invisible text until font loads (FOIT).
  • Unoptimized hero image 4MB: LCP 8.2s.

Lighthouse CI (lhci) saves metric history and posts a comment to PR with degradation. For one e‑commerce client, optimizing these metrics improved conversion by 18% and reduced server costs by $12k annually.

What does load testing solve?

k6 is a load testing tool with a JavaScript API. Scenarios are written as code, versioned in git, run in CI. Three main scenarios:

  • Spike test — sharp load increase: 0 → 1000 users in 30 seconds. Simulates a campaign launch. Shows system's ability to handle spikes.
  • Soak test — stable load for 2–4 hours. Detects memory leaks, connection pool exhaustion, performance degradation.
  • Stress test — load above expected (150–200% of peak). Shows breaking point and graceful degradation.

Thresholds:

thresholds: {
  http_req_duration: ['p95<500', 'p99<1000'],
  http_req_failed: ['rate<0.01'],
}

p95 < 500ms means 95% of requests respond faster than half a second. If threshold is not met, k6 exits with error code, CI pipeline fails.

In one online store project, we detected API degradation at the 4th hour of the test: p95 increased from 200ms to 2s due to connection leaks. After optimization, the client saved $15k per year on incident response and extra infrastructure.

Testing pyramid in a project

Level Tool Quantity Speed
Unit Vitest/Jest Many (thousands) <5 min
Integration Vitest + supertest Medium 5–15 min
E2E Playwright Few (happy path) 10–30 min
Load k6 On schedule 30–60 min
Performance Lighthouse CI On every deploy 5 min

What does the work include?

  • Audit of current coverage and identification of critical user flows.
  • Writing unit tests for key business logic, integration tests for API, E2E for user scenarios.
  • Setting up parallel execution in CI (sharded workers for Playwright).
  • Load testing with report and recommendations.
  • Test case documentation, training your team on test practices.
  • 1-month warranty support after implementation.
  • Delivery of all test artefacts (code, CI configs, run histories).

How do we work?

  1. Analysis — audit of current testing, identification of weak spots, priority setting.
  2. Design — tool selection, test plan writing, approval.
  3. Implementation — writing tests, CI integration.
  4. Testing — running all levels, result analysis, bug fixing.
  5. Deployment — going live, metric monitoring, team training.

Timeline

Setting up a full test pipeline (Jest + Playwright + k6 + Lighthouse CI) from scratch: 2–4 weeks. E2E test coverage of an existing project (20–30 scenarios): 3–6 weeks. Load testing with report and recommendations: 1–2 weeks. Cost calculated individually after audit.

Ready to discuss your project? Leave a request — we will audit your current web application testing for free and propose a plan that can save up to 60% on incident costs. Get a consultation on web application testing — contact us today.