tile38/internal/server
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
..
aof.go Replaced boxtree for rbang 2019-09-12 18:42:53 -07:00
aofmigrate.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
aofshrink.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
atomic.go Removed unused atomics 2018-11-23 01:39:04 -07:00
atomic_test.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
bson.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
checksum.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
client.go Removed evio option 2019-04-26 11:50:49 -07:00
config.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
crud.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
dev.go Minimize AOF buffer releases 2019-09-03 17:01:26 -07:00
expire.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
expression.go Better naming and comments. 2019-06-13 13:33:07 -07:00
fence.go Added TIMEOUT command 2019-04-24 05:09:41 -07:00
follow.go Recycle aof buffer 2019-03-10 10:48:14 -07:00
hooks.go Replaced boxtree for rbang 2019-09-12 18:42:53 -07:00
json.go Fix JSET cancels expiry 2019-10-08 09:45:46 -07:00
json_test.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
keys.go Fixing KEYS command and tests 2019-01-14 11:06:12 -07:00
live.go Fix invalid pubsub format for json output 2019-10-28 12:51:44 -07:00
output.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
pubsub.go Fix invalid pubsub format for json output 2019-10-28 12:51:44 -07:00
readonly.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
respconn.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
scan.go Rework timeouts to allow prepending any command with the TIMEOUT seconds 2019-04-25 14:15:53 -07:00
scanner.go Fixed nearby json field results showing wrong data 2019-05-28 12:17:59 -07:00
scripts.go Fix JSET cancels expiry 2019-10-08 09:45:46 -07:00
search.go Fixed invalid count for nearby queries 2019-08-22 15:53:37 -07:00
server.go Fix excessive memory usage for objects with TTLs 2019-10-29 11:19:33 -07:00
stats.go GC pauses be gone 2019-09-04 12:47:30 -07:00
stats_cpu.go Fix windows build issue 2018-11-05 10:58:01 -07:00
stats_cpu_darlin.go Replaced net package with evio 2018-10-28 15:51:47 -07:00
test.go Add area expressions. 2019-06-10 14:47:42 -07:00
token.go Fix parser for multiple negations. 2019-06-14 10:02:26 -07:00
token_test.go Replaced net package with evio 2018-10-28 15:51:47 -07:00