← Blog

Websites and game servers sleep when nobody uses them

A website with no visits, or a game server with no players, sleeps after 5 minutes and pays only for its files. The first visitor or player wakes it.

Most small apps spend most of the day waiting. A bakery's website gets its visits in the morning and at lunch. A Minecraft server for a group of friends is busy for a few hours in the evening. On a rented server, or on a host that charges by the month, you pay for the hours they wait as much as for the hours they work.

Estiba already charged by the second for the memory and processor an app uses. But an app that waits still holds its memory. So this week went into the other half: an app nobody is using stops, and starts again when someone shows up.

A visit wakes a website

Websites have slept since last Sunday. A service with a domain, no ports and not set to stay on goes to sleep when nobody has visited for a while. That was 15 minutes at first; since Wednesday it is 5.

When a visit arrives for a sleeping website, Estiba starts it and holds the visit until the app is listening, then passes it on. The visitor sees the page load a little slower, and nothing else. How long that takes is how long your app takes to start: our own landing page answers in about a quarter of a second from asleep. A visit waits up to 90 seconds, so even an app with a big image that has to be downloaded again gets there. In the first days, the very first visit could get an error while the app started; since Monday it waits for the app instead.

In the dashboard, a sleeping app's badge reads Sleeping, and the service's settings have "When it runs": Sleeps without visits, or Always on.

The "When it runs" choice in a service's settings, with "Sleeps without visits" selected and "Always on" beside it

Game servers sleep too

Today the same works for apps with ports, such as game servers. After 5 minutes with nobody connected, the server sleeps. A player who joins wakes it.

Games do not speak in web pages, so waking works differently. While the server sleeps, a new connection to its port gets no answer at all. Game clients try again, and a second try from the same address within 10 seconds counts as someone knocking: Estiba wakes the server. A port scanner sends one packet and moves on, so it does not wake anything. Once the game is listening, the player's next try gets in, and the server sees the player's own IP.

In practice: Minecraft may tell the first player it cannot connect, and joining again a little later works, once the world has loaded. A big world takes as long to load as it always did.

A service page of a Minecraft server asleep, with its Sleeping badge, its public port and its details

Updates wait for the last player

The same idea runs the other way for updates. A game server set to update by itself used to restart as soon as a new version of its image came out, and that kicked everyone off. Now it waits until nobody is connected, then updates. Meanwhile its page shows that a new version is out, with an Update button to install it right away if you want. Websites update as before.

When to keep it awake

Sleeping is the default, and it suits most sites and game servers. Some apps have to stay on:

  • an app with scheduled jobs, or other work it does on its own without visits;
  • a game server listed in a public server list, which checks on it while nobody plays;
  • a database, which other apps expect to find at once.

Your AI looks at the code when it deploys and keeps those always on. You can also ask it to, or change it in the service's settings. Apps with no domain and no ports, such as a Discord bot, never sleep, since nothing would arrive to wake them.

One thing to know: when an app sleeps, its container is removed, and a new one starts at the next visit. Files it wrote outside a volume are gone, as after any deployment. Anything it must keep belongs in a volume.

What it means for the bill

Asleep, an app uses no memory and no processor, so it pays for neither. It pays only for what its volume holds, if it has one, at $0.10 per GB a month.

With today's prices, $4 per GB of memory and $8 per busy processor a month:

  • A website that holds 250 MB costs $1.00 a month in memory if it is always on. Awake 3 hours a day, counting the 5 minutes after each last visit, it comes to about $0.13, plus the processor time it uses while awake.
  • A Minecraft server that holds 2 GB costs $8 a month in memory always on. Played 4 hours a day, it comes to about $1.33, plus what the players add in processor time while they play and its world at $0.10 per GB.

How it works underneath

Once a minute, the server running an app counts the connections to it. After 5 minutes with none, it marks the app as sleeping, saves its last log lines and removes its container. From then on, a visit to its domain first asks Estiba to wake it. Waking starts a new container of the same version the app ran, without a new deployment, and the visit goes through once the app answers on its port. For game ports, the server notes the second knock from an address and starts the app the same way.

Measuring connections rather than requests means a player who is idle on the server, or a browser with a page open on a live connection, still counts as someone there.

Try it

Sleeping is on by default. Deploy as usual and tell your AI what the app is:

Put my Minecraft server on Estiba and let it sleep when nobody plays

How sleeping and waking work is in Deploy an app, and the Minecraft details are in Minecraft server hosting.

Ask your AI about Estiba

It opens with the question already written. We left a summary just for it, so it answers right and spends few tokens.