Commit graph

34 commits

Author SHA1 Message Date
Shahar Mike
d7351b315e
refactor: Use DbContext, OpArgs and Transaction to access DbSlice (#3311)
This is a refactor that will put us closer to adding namespaces, see
included `docs/namespaces.md`
2024-07-12 08:13:16 +03:00
Roman Gershman
b61c722f84
chore: Add 'memory arena show' command (#3298)
* chore: Add 'memory arena show' command

Its output goes to stdout.
---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-07-10 07:20:17 +00:00
Roman Gershman
5534ee5c23
chore: minor fixes (#3082)
1. script errors are now logged continously but at most 5 per second.
2. "memory arena" is introduced - it prints the arena stats per thread.
   "memory malloc-stats" now only prints the global stats.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-05-26 10:14:02 +03:00
Roman Gershman
5bf7e3b146
chore: update helio together with new mimalloc version (#3040)
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-05-13 12:48:05 +03:00
Borys
3dd6c4959c
feat: add defragment command (#3003)
* feat: add defragment command and improve auto defragmentation algorithm
2024-05-08 14:26:42 +03:00
Vladislav
1a5eacca87
chore: Pull helio with new future (#2944) 2024-04-22 20:18:10 +03:00
Roman Gershman
f7292de4e7
chore: Introduce fiber stack allocator (#2730)
1. Use clib malloc for allocating fiber stacks but reduce the fiber stack size.
   clib malloc uses default 4K OS pages when reserving memory from the OS.
   The reason for not using mi_malloc, because we use 2MB large OS pages with mimalloc.
   However, allocating stacks is one of the cases, when using smaller 4KB memory pages is actually more
   RSS efficient because memory pages become hot at better granularity.

2. Add "memory_fiberstack_vms_bytes" metric exposing fiber stack vm usage.
3. Fix macos dependencies & update ci versions.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-03-18 13:51:33 +02:00
Shahar Mike
9ba532a826
feat(server): Use mimalloc in SSL calls (#2710)
* feat(server): Use mimalloc in SSL calls

Until now, OpenSSL used `malloc()` directly. This PR overrides it to use
mimalloc.

Fixes #2709

* Add generate-tls-files.sh
2024-03-11 08:25:59 +02:00
Roman Gershman
b38024ba4f
chore: add malloc-based stats and decommit (#2692)
* chore: add malloc-based stats and decommit

Provides more stats and control with glibc-malloc based allocator.
For example,
with v1.15.0 (--proactor_threads=2), empty database, `info memory`returns

```
used_memory:614576
used_memory_human:600.2KiB
used_memory_peak:614576
used_memory_peak_human:600.2KiB
used_memory_rss:19922944
used_memory_rss_human:19.00MiB
```

then during `memtier_benchmark  -n 300000  --key-maximum 100000 --ratio 0:1 --threads=30 -c 100` (i.e GET-only with 3k connections):

```
used_memory:614576
used_memory_human:600.2KiB
used_memory_peak:614576
used_memory_peak_human:600.2KiB
used_memory_rss:59985920
used_memory_rss_human:57.21MiB
used_memory_peak_rss:59985920
```

connections overhead grows by ~39MB.
when the traffic stops, `used_memory_rss_human` becomes `30.35MiB`
and we do not know where 11MB gets lost and `MEMORY DECOMMIT` does not reduce the RSS.

With this change, `memory malloc-stats` return during the memtier traffic
```
malloc arena: 394862592
malloc fordblks: 94192
```
i.e. 395MB virtual memory was allocated by malloc and only 94KB is chunks available for reuse.
395MB is arena virtual memory, and not RSS obviously, but at least we have some visibility into malloc reservations.
The RSS usage is the same ~57MB and the difference between virtual and RSS is due to the fact we reserve fiber stacks of size 131KB but we touch less.
After the traffic stops, `arena` is reduced to 134520832 bytes, and fordblks are 133016592, i.e. majority of reserved ranges are also free (available to reuse) in the malloc pools.
RSS goes down similarly to before to ~31MB.

So far, this PR only demonstrated the increased visibility to mmapped ranges reserved by glibc malloc.
The additional functional change is in `MEMORY DECOMMIT` that now trims malloc RSS usage from reserved but unused (fordblks) pages
by calling `malloc_trim`.
After the call, RSS is: `used_memory_rss_human:20.29MiB` which is almost the same as when we started the empty process.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

* chore: fix build for older glibc environments

Disable these extensions for alpine and use legacy version
for older glibc libraries.
---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-03-06 13:11:44 +00:00
Roman Gershman
336d6ff181
Update helio (#2538)
chore: UpdateHelio dependency

Add support for asan/ubsan checkers in our dev environment.
Remove more clang warnings.

Once we fix all the problems we will enable them in our CI as well.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-02-06 11:57:26 +02:00
Shahar Mike
b71d0f6383
feat(server): Add MEMORY TRACK ADDRESS command (#2513)
* feat(server): Add `MEMORY TRACK ADDRESS` command

Given a hex address, it replies with whether or not this address is
currently allocated by mimalloc's backing heap.

* init!

* Add HELP message
2024-02-01 21:31:08 +02:00
Shahar Mike
b2bdb0f683
feat(server): Memory tracker (#2501)
* feat(server): Memory tracker

* PR comments
2024-01-30 12:44:07 +02:00
Roman Gershman
6e6dc2c3c8
fix: do not return an error in memory-usage command (#2405)
Fixes #2399

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-01-11 21:30:37 +02:00
Roman Gershman
0e72846457
chore: consolidate facade stats under a single struct (#2368)
* chore: consolidate facade stats under a single struct

Remove connection stats from server state and move them under FacadeStats.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

* chore: fixing comments

---------

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2024-01-03 08:09:00 +00:00
Roman Gershman
8bd43497f2
feat: expose tx_queue_len metric (#2330)
This metric shows how much the transaction queue of dragonfly is loaded.
Also, output free text, human intended replies as verbatim.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-12-24 11:31:50 +02:00
Shahar Mike
a98ba6a0f8
fix(memory): Add missing fields in connection memory (#2306)
While at it, fix initialization of replication info, to correctly
account for replication connections.
2023-12-17 10:37:35 +02:00
Borys
33d0879416
refactor: conn_context and reply_builder refactoring (#2251)
* refactor: conn_context and reply_builder refactoring
2023-12-06 08:23:32 +02:00
Shahar Mike
d6292ba6fd
feat(server): Better connection memory tracking (#2205) 2023-11-26 14:51:52 +02:00
Shahar Mike
87ee4f486c
fix(stats): Do not crash upon issuing mem stats (#2169)
* fix(stats): Do not crash upon issuing `mem stats`

The reason for the crash is that we can't use a mutex while iterating
connections. It uses a non-Fiber `Await()`, and it also has a fiber
atomic guard.

Instead use the common trick of allocating per-thread data and aggregate
afterward.

* Use pool size
2023-11-14 13:12:13 +02:00
Shahar Mike
5ca2be1185
feat: Memory stats (#2162) 2023-11-13 13:58:29 +02:00
Roman Gershman
3095d8a168
feat: add 'memory decommit' command (#2058)
This command forces the memory manager to decommit memory pages back to the OS.
In addition, fixed some positional bugs in "memory malloc-stats"

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-10-23 16:49:00 +03:00
Roman Gershman
8d1474aeac
fix: improve performance of listpack sorted sets (#1885)
1. Cherry-pick changes from Redis 7 that encode integer scores more efficiently
2. Introduces optimization that first checks if the new element should be the last
   for listpack sorted sets.
3. Consolidates listpack related constants and tightens usage for listpack.
4. Introduce MEMORY USAGE command.
5. Introduce a small delay before decommitting memory pages back to OS.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-09-19 19:52:34 +03:00
Roman Gershman
36be222091
chore: add macos daily build (#1795)
It compiles most of the code though some linking problems still exist.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-09-06 09:35:11 +03:00
Roman Gershman
5aa63a68dd
chore: add clear metric for the fragmentation waste (#1735) 2023-08-24 20:17:12 +03:00
Vladislav
a12ddfe108
Remove cmd name from args (#1057)
chore: remove cmd name from the list of arguments

Signed-off-by: Vladislav Oleshko <vlad@dragonflydb.io>
Co-authored-by: Roman Gershman <roman@dragonflydb.io>
2023-04-10 14:14:52 +03:00
Vladislav
72f67eddd8
refactor(facade): Refactor reply builder (#991)
Refactor RedisReplyBuilder to simplify method overloads
2023-03-26 12:52:40 +03:00
chakaz
9add31e20f Get DragonDB to compile with clang.
While at it, fix some compile warnings, 2 of them are actual bugs
(missing virtual d'tor).

Signed-off-by: chakaz <chakaz@chakaz>
2023-03-18 11:02:37 +02:00
Roman Gershman
3ba46a5097
feat(server): Extend malloc-stats command functionality. (#775)
1. Remove dangerous check-fail in SegmentAllocator.
2. Allow printing heap stats for both backing and data heaps.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2023-02-11 07:17:48 +02:00
Roman Gershman
c2294e1298
fix: Fix bugs around rdb save and improve memory accounting (#495)
Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-11-16 12:19:35 +02:00
Roman Gershman
f8f3eac960
feat(server): Allow sampling arena stats from a specified thread (#428)
Also update dense_set.md with a reproducable test on how to see memory differences
of DenseSet vs RedisDict.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-10-24 13:25:31 +03:00
Roman Gershman
ab72ff797c
fix(server): remove double decrement of obj_memory_usage. (#406)
Also, add timing stats to malloc-stats command.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-10-19 14:32:03 +03:00
cui fliter
4e651f8d0f
fix some typos (#398)
Signed-off-by: cui fliter <imcusg@gmail.com>
2022-10-18 14:56:17 +03:00
Roman Gershman
3901786316
chore(server): Improve malloc-stats output (#370)
Now it will print deduplicated lines, shortening the table
dramatically. Also it's now easier to import it into excel.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-10-10 15:03:54 +03:00
Roman Gershman
d93eb8a5b5
feat(server): Implement MEMORY MALLOC-STATS command (#363)
Signed-off-by: Roman Gershman <roman@dragonflydb.io>

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
2022-10-06 16:45:06 +03:00