tile38/internal
tidwall 23b016d192 Fix excessive memory usage for objects with TTLs
This commit fixes an issue where Tile38 was using lots of extra
memory to track objects that are marked to expire. This was
creating problems with applications that set big TTLs.

How it worked before:

Every collection had a unique hashmap that stores expiration
timestamps for every object in that collection. Along with
the hashmaps, there's also one big server-wide list that gets
appended every time a new SET+EX is performed.

From a background routine, this list is looped over at least
10 times per second and is randomly searched for potential
candidates that might need expiring. The routine then removes
those entries from the list and tests if the objects matching
the entries have actually expired. If so, these objects are
deleted them from the database. When at least 25% of
the 20 candidates are deleted the loop is immediately
continued, otherwise the loop backs off with a 100ms pause.

Why this was a problem.

The list grows one entry for every SET+EX. When TTLs are long,
like 24-hours or more, it would take at least that much time
before the entry is removed. So for databased that have objects
that use TTLs and are updated often this could lead to a very
large list.

How it was fixed.

The list was removed and the hashmap is now search randomly. This
required a new hashmap implementation, as the built-in Go map
does not provide an operation for randomly geting entries. The
chosen implementation is a robinhood-hash because it provides
open-addressing, which makes for simple random bucket selections.

Issue #502
2019-10-29 11:19:33 -07:00
..
assets Added small logo 2019-01-19 10:45:31 -07:00
bing Faster point in polygon / GeoJSON updates 2018-10-13 04:30:48 -07:00
clip Typo causing a bug in polygon clipping 2019-02-08 13:56:43 -08:00
collection Replaced boxtree for rbang 2019-09-12 18:42:53 -07:00
deadline Rework timeouts to allow prepending any command with the TIMEOUT seconds 2019-04-25 14:15:53 -07:00
endpoint Use WaitTimeout for MQTT 2019-10-08 11:13:18 -07:00
expire Fixed data race for hooks with ttls 2019-10-08 09:26:55 -07:00
glob Faster point in polygon / GeoJSON updates 2018-10-13 04:30:48 -07:00
hservice Faster point in polygon / GeoJSON updates 2018-10-13 04:30:48 -07:00
log log: fix typo in Fatalf func 2019-05-17 13:24:05 +03:00
server Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00