From ab7dcea1b01cda3f01e58927004b4f270f5ce4da Mon Sep 17 00:00:00 2001 From: Bastian Krol Date: Mon, 7 Nov 2022 13:39:12 +0100 Subject: [PATCH] refactor(sdk): rename reproducers to examples --- .../test/tracing/sdk/examples/README.md | 49 ++++++++++++++++ .../async_recursive.js | 0 ...async_recursive_entry_intermediate_exit.js | 0 .../async_set_interval.js | 0 .../callback_recursive.js | 0 .../callback_set_interval.js | 0 .../promise_recursive.js | 0 .../promise_set_interval.js | 0 .../util.js | 0 .../sdk/memory_leak_reproducer/README.md | 57 ------------------- 10 files changed, 49 insertions(+), 57 deletions(-) create mode 100644 packages/collector/test/tracing/sdk/examples/README.md rename packages/collector/test/tracing/sdk/{memory_leak_reproducer => examples}/async_recursive.js (100%) rename packages/collector/test/tracing/sdk/{memory_leak_reproducer => examples}/async_recursive_entry_intermediate_exit.js (100%) rename packages/collector/test/tracing/sdk/{memory_leak_reproducer => examples}/async_set_interval.js (100%) rename packages/collector/test/tracing/sdk/{memory_leak_reproducer => examples}/callback_recursive.js (100%) rename packages/collector/test/tracing/sdk/{memory_leak_reproducer => examples}/callback_set_interval.js (100%) rename packages/collector/test/tracing/sdk/{memory_leak_reproducer => examples}/promise_recursive.js (100%) rename packages/collector/test/tracing/sdk/{memory_leak_reproducer => examples}/promise_set_interval.js (100%) rename packages/collector/test/tracing/sdk/{memory_leak_reproducer => examples}/util.js (100%) delete mode 100644 packages/collector/test/tracing/sdk/memory_leak_reproducer/README.md diff --git a/packages/collector/test/tracing/sdk/examples/README.md b/packages/collector/test/tracing/sdk/examples/README.md new file mode 100644 index 0000000000..d0776de903 --- /dev/null +++ b/packages/collector/test/tracing/sdk/examples/README.md @@ -0,0 +1,49 @@ +SDK Examples +============ + +This directory contains a couple of small test applications that use the Instana Node.js tracing SDK. + +They all create an entry span in regular intervals via the SDK. They do not need to be triggered by an external request. + +Available Examples +--------------------- + +There are currently six different examples, two for each SDK API style: `async`, `promise`, and `callback`. + +One of each pair is using a *recursive* call pattern. That is, the next call is triggered from the context of the previous call. The call is triggerd via `setTimeout` but that does not matter with respect to AsyncLocalStorage (ALS for short)/cls-hooked, because the context is kept across `setTimeout` (or any async mechanism – this is precisely the point of ALS/cls-hooked). Note: This particular usage pattern used to create memory issues up until version `@instana/collector@2.11.0`, which lead to increased CPU usage. This has been fixed with version `2.11.1` + +The other type of example apps schedule calls regularly via `setInterval`. The crucial difference is that calls are not triggered from the context of the preceding call, but from the root context. + +Usage +----- +The SDK will only actually create spans when `@instana/collector` has established a connection to an agent. To run the examples, you therefore need to start an agent locally. + +If you are not interested in inspecting the reported data in Instana, you can start +``` +DROP_DATA=true node packages/collector/test/apps/agentStub +``` + +in a separate shell. Otherwise, start an Instana agent locally. Be aware that the examples will create a lot of spans very quickly, though. (This can be controlled with the `DELAY` environment variable, see below.`) + +Start an example app like this: + +``` +node packages/collector/test/tracing/sdk/examples/async_recursive.js +``` + +There are a couple of options to control the behavior: + +``` +# Set a custom delay in milliseconds between individual calls. The default is currently 10 (!) milliseconds. +DELAY=1000 node packages/collector/test/tracing/sdk/examples/async_recursive.js + +# Force @instana/collector to use the legacy cls-hooked library instead of AsyncLocalStorage. +INSTANA_FORCE_LEGACY_CLS=true node packages/collector/test/tracing/sdk/examples/async_recursive.js + +# Print additional debug output +DEBUG_CLS=true node packages/collector/test/tracing/sdk/examples/async_recursive.js +``` + +### Creating a Heapdump + +All examples load the `heapdump` module. Execute `kill -USR2 $pid` to create a heapdump while the process is running. Heapdumps can be inspected via Chrome/Chromium for example (DevTools -> tab memory -> Load). diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/async_recursive.js b/packages/collector/test/tracing/sdk/examples/async_recursive.js similarity index 100% rename from packages/collector/test/tracing/sdk/memory_leak_reproducer/async_recursive.js rename to packages/collector/test/tracing/sdk/examples/async_recursive.js diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/async_recursive_entry_intermediate_exit.js b/packages/collector/test/tracing/sdk/examples/async_recursive_entry_intermediate_exit.js similarity index 100% rename from packages/collector/test/tracing/sdk/memory_leak_reproducer/async_recursive_entry_intermediate_exit.js rename to packages/collector/test/tracing/sdk/examples/async_recursive_entry_intermediate_exit.js diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/async_set_interval.js b/packages/collector/test/tracing/sdk/examples/async_set_interval.js similarity index 100% rename from packages/collector/test/tracing/sdk/memory_leak_reproducer/async_set_interval.js rename to packages/collector/test/tracing/sdk/examples/async_set_interval.js diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/callback_recursive.js b/packages/collector/test/tracing/sdk/examples/callback_recursive.js similarity index 100% rename from packages/collector/test/tracing/sdk/memory_leak_reproducer/callback_recursive.js rename to packages/collector/test/tracing/sdk/examples/callback_recursive.js diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/callback_set_interval.js b/packages/collector/test/tracing/sdk/examples/callback_set_interval.js similarity index 100% rename from packages/collector/test/tracing/sdk/memory_leak_reproducer/callback_set_interval.js rename to packages/collector/test/tracing/sdk/examples/callback_set_interval.js diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/promise_recursive.js b/packages/collector/test/tracing/sdk/examples/promise_recursive.js similarity index 100% rename from packages/collector/test/tracing/sdk/memory_leak_reproducer/promise_recursive.js rename to packages/collector/test/tracing/sdk/examples/promise_recursive.js diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/promise_set_interval.js b/packages/collector/test/tracing/sdk/examples/promise_set_interval.js similarity index 100% rename from packages/collector/test/tracing/sdk/memory_leak_reproducer/promise_set_interval.js rename to packages/collector/test/tracing/sdk/examples/promise_set_interval.js diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/util.js b/packages/collector/test/tracing/sdk/examples/util.js similarity index 100% rename from packages/collector/test/tracing/sdk/memory_leak_reproducer/util.js rename to packages/collector/test/tracing/sdk/examples/util.js diff --git a/packages/collector/test/tracing/sdk/memory_leak_reproducer/README.md b/packages/collector/test/tracing/sdk/memory_leak_reproducer/README.md deleted file mode 100644 index b197cb87eb..0000000000 --- a/packages/collector/test/tracing/sdk/memory_leak_reproducer/README.md +++ /dev/null @@ -1,57 +0,0 @@ -SDK Memory Leak Reproducer -========================== - -This directory contains a couple of small test applications that try to reproduce a memory leak in the SDK, or rather, in our use of AsyncLocalStorage/cls-hooked. - -They all create an entry span in regular intervals via the SDK. They do not need to be triggered by an external request. - -Available Reproducers ---------------------- - -There are currently six different reproducers, two for each SDK API style: -* async, -* promise, and -* callback. - -One of each pair is using a *recursive* call pattern. That is, the next call is triggered from the context of the previous call. The call is triggerd via `setTimeout` but that does not matter with respect to AsyncLocalStorage (ALS for short)/cls-hooked, because the context is kept across `setTimeout` (or any async mechanism – this is precisely the point of ALS/cls-hooked). - -The other reproducer is scheduling regular calls via `setInterval`. The crucial difference is that calls are not triggered from the context of the preceding call, but from the root context. - -The current hypothesis is that all recursive reproducers are affected by the leak, no matter which API style the use or whether they use ALS or the legacy cls-hooked implementation. Additionally, some of the non-recursive reproducers might also be affected due to the failure of existing the context after Namespace#runPromise. - -Usage ------ -The SDK will only actually create spans when @instana/collector has established a connection to an agent. To run the examples, you therefore need to start an agent locally. - -If you are not interested in inspecting the reported data in Instana, you can start -``` -DROP_DATA=true node packages/collector/test/apps/agentStub -``` - -in a separate shell. Otherwise, start an Instana agent locally. Be aware that the reproducers will create a lot of spans, though. - -Start a reproducer like this: - -node packages/collector/test/tracing/sdk/memory_leak_reproducer/async_recursive.js - -There are a couple of options to control the behavior: - -``` -# Set a custom delay in milliseconds between individual calls. The default is currently 10 (!) milliseconds. -DELAY=1000 node packages/collector/test/tracing/sdk/memory_leak_reproducer/async_recursive.js - -# Force @instana/collector to use the legacy cls-hooked library instead of AsyncLocalStorage. -INSTANA_FORCE_LEGACY_CLS=true node packages/collector/test/tracing/sdk/memory_leak_reproducer/async_recursive.js - -# Print additional debug output -DEBUG_CLS=true node packages/collector/test/tracing/sdk/memory_leak_reproducer/async_recursive.js -``` - -### Creating a Heapdump - -All reproducers load the `heapdump` module. Execute `kill -USR2 $pid` to create a heapdump while the process is running. Heapdumps can be inspected via Chrome/Chromium for example (DevTools -> tab memory -> Load). - -Analysis --------- - -The detailed analysis is currently not available in publicly. The internal link is: https://www.notion.so/instana/SDK-Memory-Leak-a807a1b242c84976ac79d9a1a9037494