---
title: "Cut time to first byte on a VPS: what the server controls · CloudSat"
description: "Measure time to first byte with curl, split network from server time, then cut both with a closer region, TLS 1.3, HTTP/3, page caching and slow query logs."
url: https://cloudsat.io/learn/cut-time-to-first-byte-on-a-vps
updated: 2026-11-18T12:00:00Z
source: CloudSat (https://cloudsat.io/). Prices in USD.
---

[Cloud and hosting](https://cloudsat.io/learn/topic/cloud-infrastructure)

# Cut time to first byte on a VPS: what the server controls

Measure time to first byte with curl, split network from server time, then cut both with a closer region, TLS 1.3, HTTP/3, page caching and slow query logs.

CloudSat team November 18, 2026 7 min read

Most of page speed is decided in the browser: images, scripts, fonts and layout. One part belongs to the server: time to first byte (TTFB), the wait between asking for a page and receiving the first byte of the answer. web.dev counts redirects, DNS lookup, connection and TLS setup and the server's own response time in it, and treats 0.8 seconds or less as good and more than 1.8 seconds as poor. TTFB is not one of the Core Web Vitals, but everything waits for it, including Largest Contentful Paint, which should happen within 2.5 seconds for 75% of page loads. This guide measures where the time goes and fixes the parts a server controls.

## Measure before you change anything

curl reports each phase of a request. The values are cumulative seconds from the start:

```bash
curl -o /dev/null -s -w 'dns %{time_namelookup}  connect %{time_connect}  tls %{time_appconnect}  ttfb %{time_starttransfer}  total %{time_total}\n' https://example.com/
```

Subtract neighbors to get each phase:

| Phase | Calculation | What drives it |
| --- | --- | --- |
| DNS | `time_namelookup` | Resolver, record TTLs |
| TCP connect | `time_connect` minus DNS | Distance: one round trip |
| TLS handshake | `time_appconnect` minus connect | Distance, TLS version |
| Server | `time_starttransfer` minus `time_appconnect` | Your application, database and cache, plus one round trip |

Run it several times, because the first request may pay for a cold DNS cache or an idle worker. Then run it from the server itself, which removes the network from the picture while keeping the right host name and certificate:

```bash
curl -o /dev/null -s -w 'ttfb %{time_starttransfer}\n' --resolve example.com:443:127.0.0.1 https://example.com/
```

If the page is slow even from the server, the application is the problem. If it is fast locally but slow from your visitors' country, look at distance, redirects and the TLS setup. For real visitors, PageSpeed Insights shows field TTFB from Chrome users when the site has enough traffic, and the Timing tab of the browser's developer tools splits the same phases for one request.

Measure the pages that matter, not only the home page. Search, product pages and anything served to logged-in users usually skip the caches and are often the slow ones.

## Make the server explain its time

The `Server-Timing` response header lets the application report its own phases, and browsers display them in the developer tools next to the network timings:

```http
Server-Timing: db;dur=182, render;dur=41, cache;desc="miss"
```

Most frameworks have middleware that adds it. It is visible to anyone, so keep metric names vague in production or send the header only to your own address. On the proxy side, log how long each upstream took to start answering:

```nginx
log_format timing '$remote_addr "$request" $status rt=$request_time '
                  'uct=$upstream_connect_time uht=$upstream_header_time';

access_log /var/log/nginx/timing.log timing;
```

`$upstream_header_time` is the application's own time to first byte as nginx saw it. When it is close to the TTFB visitors get, the network is not your problem.

## Distance: put the server near your visitors

Before the first request can be sent, a new HTTPS connection over TCP needs one round trip for the TCP handshake and one more for a TLS 1.3 handshake, or two more with TLS 1.2. HTTP/3 runs over QUIC, which combines transport and TLS setup into one round trip. Every round trip costs what the distance costs, and no tuning on the server makes it shorter. Two rules follow:

- **Host close to the bulk of your audience.** The [locations page](https://cloudsat.io/locations) lists CloudSat's 13 regions in the United States, Europe, the Gulf and Asia-Pacific.
- **Remove redirect chains.** `http://example.com` to `https://example.com` to `https://www.example.com` spends round trips before any content. Link the final URL everywhere, and send an HSTS header so returning browsers go straight to HTTPS.

When the audience spans continents, a CDN in front of cached pages and static files does what one server location cannot.

## Protocol settings that save round trips

- **TLS 1.3 and HTTP/2**: on by default in Caddy. In nginx, `ssl_protocols TLSv1.2 TLSv1.3;` is the default in current versions (check that your distribution's `nginx.conf` does not list older ones), and HTTP/2 is `http2 on;` from 1.25.1, or `listen 443 ssl http2;` on older builds.
- **Session resumption**: let returning visitors skip part of the handshake. In nginx, add `ssl_session_cache shared:SSL:10m;`.
- **HTTP/3**: Caddy serves it by default once UDP 443 is open. In nginx it needs the HTTP/3 module and a `quic` listener; our comparison of [Caddy and Nginx as a reverse proxy](https://cloudsat.io/learn/caddy-or-nginx-reverse-proxy) shows both setups.
- **Compression**: gzip, Brotli or zstd do not make the first byte arrive sooner, but they shorten everything after it. In nginx, `gzip on;` compresses only HTML unless you list more types in `gzip_types`. Precompress static files at build time rather than compressing them hard on every request.

## Make the application answer faster

### Cache whole pages when you can

A page that looks the same for every anonymous visitor does not need to be rendered for each of them. Even a few seconds of caching in nginx turns a traffic spike into one backend request per URL:

```nginx
proxy_cache_path /var/cache/nginx/app levels=1:2 keys_zone=app:10m max_size=1g inactive=10m use_temp_path=off;

server {
    # listeners, certificates and proxy headers as usual
    location / {
        proxy_cache app;
        proxy_cache_valid 200 301 10s;
        proxy_cache_use_stale error timeout updating;
        proxy_cache_lock on;
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        add_header X-Cache-Status $upstream_cache_status;
        proxy_pass http://127.0.0.1:3000;
    }
}
```

`proxy_cache_use_stale updating` serves the old copy while one request refreshes it, and `proxy_cache_lock` stops simultaneous misses from all reaching the app. Replace `session` with your application's login cookie, so signed-in users always get fresh pages. nginx already refuses to cache responses that set cookies. Check `X-Cache-Status` with `curl -sI` to confirm hits.

### Find the slow queries

Database time is the usual bulk of a slow uncached page. Log what takes longer than half a second in MariaDB or MySQL:

```ini
# /etc/mysql/mariadb.conf.d/60-slow.cnf
[mysqld]
slow_query_log      = 1
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time     = 0.5
```

In PostgreSQL, the same takes two statements:

```sql
ALTER SYSTEM SET log_min_duration_statement = '500ms';
SELECT pg_reload_conf();
```

Run `EXPLAIN` on the worst offenders and add the missing indexes. A page that sends hundreds of fast queries will not show up here; count queries per request in your framework's debug tools to catch that pattern. Frequently computed results belong in an object cache such as Redis or Valkey.

### Profile the code path

For PHP, confirm OPcache is enabled and set `request_slowlog_timeout` and `slowlog` in the PHP-FPM pool, which then writes a stack trace for every request slower than the limit. For Python, `py-spy top --pid <pid>` shows live where a worker spends its time without restarting it. Watch for queueing too: when every worker is busy, new requests wait for a free one, and TTFB climbs under load even though each request alone is fast. Size the worker pool from memory, and add workers before adding cleverness.

If profiling shows requests bound by CPU, per-core speed matters more than core count, because most runtimes handle one request on one core. CloudSat's [High Frequency VPS](https://cloudsat.io/high-frequency-vps) runs on AMD Ryzen at 4.2 GHz or more for that kind of load.

## Let browsers keep static files

Give fingerprinted assets, such as `app.3f9c2a.js`, a year-long lifetime so repeat visits never ask for them again:

```nginx
location ~* \.(css|js|woff2|svg|png|jpg|webp|avif)$ {
    add_header Cache-Control "public, max-age=31536000, immutable";
}
```

Use this only for files whose names change when their content does. HTML should stay short-lived, or be purged from caches on every publish.

## Work in this order

1. Measure from your visitors' region and from the server itself.
2. If DNS, connect and TLS dominate: move closer, add a CDN, remove redirects, enable TLS 1.3 and HTTP/3.
3. If server time dominates: cache pages, fix slow queries, profile, then look at worker counts and CPU.
4. Measure again after each change, so you know which one helped.

## FAQ

### What is a good TTFB?

web.dev calls 0.8 seconds or less good and more than 1.8 seconds poor, as a rough guide for real visitors. A lab test from one location is only a hint; field data from your actual audience decides.

### Does a faster server fix a slow page?

Only the server's share. If TTFB is already low and the largest element still appears late, the cause is in the page itself: heavy images, render-blocking scripts or late-loading fonts.

### Is HTTP/3 worth enabling?

Usually. It saves a round trip on new connections and avoids TCP's head-of-line blocking on lossy mobile networks. The costs are opening UDP 443, and in nginx a module the documentation still marks experimental.

### Why is TTFB slow only for logged-in users?

Their pages skip the page cache by design, so every request runs the full application and database path. Profile those pages specifically, and cache fragments of them in an object cache.

**Run it on CloudSat.** Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. [See plans](https://cloudsat.io/plans) or [deploy a server](https://dash.cloudsat.io/console/deploy).

## Keep reading

[All guides in Cloud and hosting](https://cloudsat.io/learn/topic/cloud-infrastructure)

- [Size a VPS for WordPress: a buyer's checklist](https://cloudsat.io/learn/wordpress-vps-sizing-and-buyers-checklist): Cloud and hosting Size a VPS for WordPress: a buyer's checklist 7 min read
- [Caddy or Nginx as a reverse proxy for self-hosted apps](https://cloudsat.io/learn/caddy-or-nginx-reverse-proxy): DevOps Caddy or Nginx as a reverse proxy for self-hosted apps 8 min read
- [Apache, Nginx or OpenLiteSpeed for a WordPress server](https://cloudsat.io/learn/wordpress-web-server-apache-nginx-openlitespeed): DevOps Apache, Nginx or OpenLiteSpeed for a WordPress server 6 min read
- [VPS or dedicated server: measure first, then decide](https://cloudsat.io/learn/vps-or-dedicated-server-measure-first): Cloud and hosting VPS or dedicated server: measure first, then decide 6 min read
