Wolf Territories Grid

← All posts

Taming the OpenSim Asset Cache: How We Replaced Flotsam's Disk Cache with nginx

9 October 2026 · Lone Wolf

If you run an OpenSimulator grid, there is a good chance the Flotsam asset cache has bitten you at some point. It bit us again this week, so we replaced it with something far simpler. This post explains what went wrong, what we built instead, and how to do the same on your own grid. Everything here works with a stock OpenSimulator region and a stock nginx.

What went wrong

Every region keeps a local copy of the assets it uses (textures, meshes, scripts, sounds) so it does not have to ask the grid's asset server every time. In OpenSimulator that job belongs to the Flotsam asset cache, which stores every asset as its own small file on disk.

Like many grids, we pointed all the regions on a server at one shared cache folder, and we had switched off Flotsam's expiry (FileCacheTimeout = 0 and FileCleanupTimer = 0) so that assets would never be fetched twice. That sounds sensible until you do the sums. Nothing is ever removed, and every asset is a separate file. On one of our servers the cache reached 38.7 million files.

A Linux filesystem has a fixed number of inodes, one per file. When they run out, every attempt to create a file fails with "No space left on device", even with 150 GB of disk still free. Logs stop being written, regions cannot save, and everything on that server starts to misbehave.

Turning the expiry back on is not much of an answer either. Flotsam's cleanup walks the whole folder, and on a cache of tens of millions of files that walk is itself a heavy load on a busy server.

The idea: let nginx be the cache

A region fetches assets from the asset server with plain HTTP GET requests, so a standard caching web proxy can sit in between. We run nginx on each region server, listening only on the server itself, and point the regions at it instead of at the asset server. nginx keeps the cache on disk and does the housekeeping.

  • It has a hard size limit. max_size caps the bytes. When the cache is full, nginx's cache manager removes the least recently used assets by itself, little by little, with no folder walk.
  • It has a hard limit on the number of files. nginx keeps one memory slot per cached asset, about 8,000 per megabyte of keys_zone. Our 400 MB zone holds at most about 3.2 million entries, so the cache can never come near the inode limit again, whatever the asset sizes.
  • Assets never change. An asset ID always means the same bytes, so a successful reply can be kept for a long time with no need to check it again.
  • One fetch for many regions. When ten regions on a server want the same texture at the same moment, proxy_cache_lock makes one request to the asset server and hands the answer to all ten.
  • It rides out short outages. If the asset server stalls or errors, nginx can keep serving what it already has.

Flotsam stays switched on, but only as a memory cache inside each region (FileCacheEnabled = false in the [AssetCache] section). The region keeps its fast in-memory copies, and the disk side belongs to nginx.

What gets cached, and what never does

These are the paths a region uses on the asset server, taken from OpenSimulator's AssetServicesConnector:

  • GET /assets/<id>, /assets/<id>/data and /assets/<id>/metadata: cached, but only when the answer is a 200.
  • POST /assets/ (upload), POST /assets/<id> (update), DELETE /assets/<id> and POST /get_assets_exist: passed straight through and never cached.

We are careful about two kinds of reply:

  • "Not found" is never cached. A region often asks for an asset a moment before its upload has finished. If the 404 were cached, the new asset would stay invisible. Flotsam already keeps its own short negative cache, so nothing extra is needed.
  • Tiny replies are never cached. When our storage backend has had a bad moment, the asset server has sometimes answered with the asset's record but no data. Caching that would serve a broken asset for weeks. A record with no data is always under 2,000 bytes, so we simply do not store any reply that small. Scripts and notecards that small still go to the asset server every time, but they are cheap, and the region's memory cache still holds them.

Hypergrid assets do not pass through the proxy at all. OpenSimulator's region asset connector sends requests for foreign assets straight to the visitor's home grid, so Hypergrid works exactly as before.

The nginx configuration

This is the heart of it. Change the upstream to your own asset server (Robust's asset service usually listens on port 8003) and size max_size to suit your disk. We leave at least 20% of each disk free.

proxy_cache_path /var/cache/nginx/wolfassets levels=1:2 keys_zone=wolfassets:400m max_size=60g inactive=30d use_temp_path=off;
# do not cache replies under 2,000 bytes or with no Content-Length
map $upstream_http_content_length $asset_too_small { default 0; "" 1; "~^[0-9]{1,3}$" 1; "~^1[0-9]{3}$" 1; }
upstream grid_assets { server your-robust-host:8003; keepalive 32; }
server {
listen 127.0.0.1:18003;
client_max_body_size 0;
proxy_request_buffering off;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host your-robust-host:8003;
location ~ ^/assets/[^/]+(/metadata|/data)?$ {
proxy_pass http://grid_assets;
proxy_cache wolfassets;
proxy_cache_methods GET HEAD;
proxy_cache_key $request_method$request_uri;
proxy_cache_convert_head off;
proxy_cache_valid 200 365d;
proxy_no_cache $asset_too_small;
proxy_ignore_headers Cache-Control Expires Set-Cookie Vary X-Accel-Expires;
proxy_cache_lock on;
proxy_cache_lock_timeout 10s;
proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
add_header X-Cache-Status $upstream_cache_status always;
}
location / {
proxy_pass http://grid_assets;
proxy_cache off;
}
}

Then, in each region's configuration:

[AssetService]
AssetServerURI = "http://127.0.0.1:18003"
[AssetCache]
FileCacheEnabled = false

Set nginx to start at boot and to restart itself if it ever stops (Restart=always in a systemd drop-in). Make sure it is running before the regions start, because the regions now depend on it for every asset.

Make sure your settings survive

This is the part most likely to catch you out. Many grids, ours included, rebuild a region's configuration every time it starts: they copy in a template, pull shared settings files from central storage, then write the per-region values. A setting you change by hand in a region's folder can be quietly overwritten at the next start.

So we put the change in our region start-up script itself, at the point after all the copying is done. It is controlled by a single switch at the top of the script, and setting that switch to empty puts everything back as it was. After a region started, we checked its live configuration, not the files beforehand. That catches the case where something later in the start-up undoes your change.

How it went

We tried it on one region server first, letting regions move over one at a time as they came round in a normal rolling restart. The results:

  • An asset served from the nginx cache arrived in about 1.5 ms, against about 44 ms from the asset server.
  • 30 randomly chosen assets fetched through the cache were byte-for-byte identical to the asset server's copies.
  • Uploads and deletes went straight through and worked.
  • Across about 4,000 requests the cache reported no errors, and the server's load did not change.
  • One of us teleported into a region that had just moved over and described it as "lightning fast".

The next day it went out to every region server, ocean regions included, with each region switching over at its next restart. The asset server sees less traffic too, because each region server fetches an asset once and shares it with every region on that server.

Why even brand-new assets got faster

We expected assets that were already in the cache to arrive faster. What surprised us was that regions felt much faster overall, even when loading things the cache had never seen. Visiting a region full of content we had never been to before was, in the words of our grid owner, "very very very fast". When we went back to the OpenSimulator source, the reasons were plain enough:

  • The region no longer does disk work on every asset. With Flotsam's disk cache switched on, every asset request first checks whether the asset's file exists on disk, and every asset fetched from the grid is then written to disk as a brand-new file. In a cache tree of tens of millions of files, Linux cannot keep all of those file details in memory. So each check and each write could mean a trip to the disk, on a disk shared by more than a hundred busy regions. With the disk cache off, a region that does not have an asset in memory simply asks for it over the network, with no disk work at all.
  • The whole server stops fighting over the disk. All those small reads and writes, plus the clean-up passes over the huge cache, kept the disk busy for every region on the machine. Take that away and everything else that uses the disk gets faster too: region saves, script state, logs.
  • "New to you" is often not new to the server. A region server runs well over a hundred regions, and they share a great deal of content: common textures, trees, furniture, avatar parts. Something you have never seen has often just been fetched by a neighbouring region on the same server, so nginx already has it.
  • Duplicate requests are merged. When a region loads, many requests for the same popular asset arrive at once. nginx sends one request to the asset server and shares the answer, so the asset server has less work to do and answers everyone else faster.

The lesson for us: a disk cache that is too big does more than waste space. It slows everything on the server, including the requests it was never going to help with.

Retiring the old cache, gently

The obvious way to get rid of the old cache is rm -rf. Do not do that without checking first. Our storage has had bad days over the years, and a region's disk cache sometimes holds the only surviving copy of an asset: the asset server has lost its record, or one of the storage backends never received the data. In a single 10-minute test on one server, our checker found 44 assets that existed nowhere else. Across that server's whole cache, that works out to thousands of textures, meshes and notecards that a plain delete would have lost for good.

So every file is checked before it is deleted. The checker looks the asset up in the asset database. Then it confirms the data is held in both of our storage backends. Anything missing is uploaded back from the cache first, after checking the bytes match. Only then is the file removed. Files it cannot verify are kept and logged for a human to look at.

Checking every file one by one against two storage services was far too slow for tens of millions of files. So the checker now downloads the complete list of what each storage backend holds in one bulk pass, and checks against that list in memory. Anything not on the list still gets the careful one-at-a-time check and, if needed, a restore. It runs at the lowest disk and CPU priority, because our grid is in use around the clock.

In short

  • Do not let an asset cache grow without limit. Inodes run out long before disk space does.
  • A small nginx proxy_cache in front of your asset server gives you a cache with a size limit and a file limit that cleans up after itself, plus one shared fetch for all the regions on a server.
  • Never cache "not found" replies or suspiciously small replies.
  • Before deleting an old asset cache, check that every asset in it really exists in your storage. Some of them may be the last copy.
  • Apply the change where your start-up scripts cannot overwrite it, and check the live configuration afterwards.

If you run a grid and want to try this, the configuration above is all there is to it. We are happy to help: find us in-world on Wolf Territories.