RAM-based map caching to reduce server CPU usage March 27, 2018
Summary: It worked.
Profiling has long shown that map reads consume the majority of CPU resources on the server, especially in areas of the map that have a lot of full containers (each container acts as a multiplier on the amount of information that needs to be fetched for a given tile). As people walk around the map, they look at big chunks of the map all at once, and this produces dramatically more load than map writes (which only happen when a player does something). A player usually changes (writes) about one tile per second on average, but as they walk around, they might be looking at hundreds of tiles every few seconds.
I added a hash table for caching recently-read tiles from the map to make reads much less expensive. Since writes are way less frequent, they can still be expensive: changed tiles are both written to the hash table and instantly pushed into the disk-based database. Thus, the map on the disk never lags behind reality.
Additional profiling also found a few more places where I could squeeze out a few redundancies. For example, substantial load was coming from checking whether each item in a container had decayed. But most things in most containers currently don't decay at all. Might as well remember whether a container holds any decaying items or not, so we don't have to keep checking every item every time we look at the container.
The impact on CPU load can be seen above, with the whole graph representing 40 concurrent players on a cluttered map.
|
|
|