Files
neon/proxy/src
Conrad Ludgate 7cdde285a5 proxy: limit concurrent wake_compute requests per endpoint (#5799)
## Problem

A user can perform many database connections at the same instant of time
- these will all cache miss and materialise as requests to the control
plane. #5705

## Summary of changes

I am using a `DashMap` (a sharded `RwLock<HashMap>`) of endpoints ->
semaphores to apply a limiter. If the limiter is enabled (permits > 0),
the semaphore will be retrieved per endpoint and a permit will be
awaited before continuing to call the wake_compute endpoint.

### Important details

This dashmap would grow uncontrollably without maintenance. It's not a
cache so I don't think an LRU-based reclamation makes sense. Instead,
I've made use of the sharding functionality of DashMap to lock a single
shard and clear out unused semaphores periodically.

I ran a test in release, using 128 tokio tasks among 12 threads each
pushing 1000 entries into the map per second, clearing a shard every 2
seconds (64 second epoch with 32 shards). The endpoint names were
sampled from a gamma distribution to make sure some overlap would occur,
and each permit was held for 1ms. The histogram for time to clear each
shard settled between 256-512us without any variance in my testing.

Holding a lock for under a millisecond for 1 of the shards does not
concern me as blocking
2023-11-09 14:14:30 +00:00
..
2023-10-25 15:43:03 +01:00
2023-10-17 13:13:12 +01:00
2023-07-04 14:54:59 +01:00
2023-05-15 23:45:04 +02:00
2023-07-17 15:53:01 +01:00
2023-10-25 15:43:03 +01:00
2023-11-06 17:44:44 +00:00
2023-08-31 14:30:25 +03:00
2023-10-30 16:43:06 +00:00
2023-08-30 15:14:03 +01:00
2022-07-04 23:46:37 +03:00