quic: cache timestamp for address lru cache · nodejs/node@309bd49 · GitHub
Skip to content

Commit 309bd49

Browse files
jasnelladuh95
authored andcommitted
quic: cache timestamp for address lru cache
Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: #63483 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 2ce5588 commit 309bd49

8 files changed

Lines changed: 192 additions & 107 deletions

File tree

src/node_sockaddr-inl.h

Lines changed: 7 additions & 8 deletions

src/node_sockaddr.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ class SocketAddressLRU : public MemoryRetainer {
213213
// If the item already exists, returns a reference to
214214
// the existing item, adjusting items position in the
215215
// LRU. If the item does not exist, emplaces the item
216-
// and returns the new item.
217-
Type* Upsert(const SocketAddress& address);
216+
// and returns the new item. The caller provides a
217+
// timestamp to avoid redundant uv_hrtime() calls.
218+
Type* Upsert(const SocketAddress& address, uint64_t now);
218219

219220
// Returns a reference to the item if it exists, or
220221
// nullptr. The position in the LRU is not modified.
@@ -231,7 +232,7 @@ class SocketAddressLRU : public MemoryRetainer {
231232
using Pair = std::pair<SocketAddress, Type>;
232233
using Iterator = typename std::list<Pair>::iterator;
233234

234-
void CheckExpired();
235+
void CheckExpired(uint64_t now);
235236

236237
std::list<Pair> list_;
237238
SocketAddress::Map<Iterator> map_;

src/quic/defs.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,11 +378,13 @@ struct TokenBucket final {
378378
// hasn't been initialized yet (last_ts == 0). Used for per-host
379379
// buckets in the address LRU where the rate/burst aren't known
380380
// at construction time.
381-
void InitOnce(double r, double b);
381+
void InitOnce(double r, double b, uint64_t now);
382382

383383
// Try to consume one token. Refills based on elapsed time, then
384384
// attempts to consume. Returns true if the request is allowed.
385-
bool consume();
385+
// The caller provides the current timestamp to avoid redundant
386+
// uv_hrtime() calls in hot paths.
387+
bool consume(uint64_t now);
386388
};
387389

388390
class DebugIndentScope final {

src/quic/endpoint.cc

Lines changed: 81 additions & 56 deletions

0 commit comments

Comments
 (0)