Skip to content

Commit 66b3ab1

Browse files
gabelevifacebook-github-bot
authored andcommitted
Sample sharedmem stats every second too
Summary: We're sampling CGroup memory stats every second. We might as well sample the same info from shared memory. This will let us see which steps are growing our shared memory heap the most. Reviewed By: mroch Differential Revision: D16360265 fbshipit-source-id: 75bfbe3e3f343fa43d28c03fc8bcaa3ab777d970
1 parent 5d75242 commit 66b3ab1

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/services/inference/types_js.ml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,17 @@ let filter_duplicate_provider map file =
5050

5151
let with_memory_info callback =
5252
let%lwt cgroup_stats = CGroup.get_stats () in
53-
callback ~cgroup_stats;
53+
(* Reading hash_stats while workers are writing can cause assertion errors *)
54+
let hash_stats = try Some (SharedMem_js.hash_stats ()) with _ -> None in
55+
let heap_size = SharedMem_js.heap_size () in
56+
callback ~cgroup_stats ~hash_stats ~heap_size;
5457
Lwt.return_unit
5558

5659
module MemorySamplingLoop = LwtLoop.Make (struct
5760
type acc =
5861
cgroup_stats:(CGroup.stats, string) result ->
62+
hash_stats:SharedMem_js.table_stats option->
63+
heap_size:int ->
5964
unit
6065
let main callback =
6166
let%lwt () = with_memory_info callback in
@@ -87,7 +92,29 @@ let with_timer_lwt =
8792
)
8893
in
8994

90-
let sample_memory timer profiling ~cgroup_stats =
95+
let sample_memory timer profiling ~cgroup_stats ~hash_stats ~heap_size =
96+
Profiling_js.sample_memory profiling
97+
~group:timer
98+
~metric:"heap"
99+
~value:(float heap_size);
100+
101+
Option.iter hash_stats ~f:(fun {SharedMem_js.nonempty_slots; used_slots; slots;} ->
102+
Profiling_js.sample_memory profiling
103+
~group:timer
104+
~metric:"hash_nonempty_slots"
105+
~value:(float nonempty_slots);
106+
107+
Profiling_js.sample_memory profiling
108+
~group:timer
109+
~metric:"hash_used_slots"
110+
~value:(float used_slots);
111+
112+
Profiling_js.sample_memory profiling
113+
~group:timer
114+
~metric:"hash_slots"
115+
~value:(float slots)
116+
);
117+
91118
match cgroup_stats with
92119
| Error _ -> ()
93120
| Ok { CGroup.total; total_swap; anon; file; shmem; } -> begin

0 commit comments

Comments
 (0)