brianc/node-pg-copy-streams

memory usage test breaking in node v16

Closed this issue · 1 comments

This issue is created to track a behavior that seems to appear with node v16.

There is a test in the test suite called "low copy-to memory usage during large bytea streaming".

We track the external memory used by the node process during the streaming of a 64MB bytea field. In node v8, v10, v12, v14, via interim garbage collections, the test manages to show that the external memory used can stay under 20MB.

In node v16, the external memory used does not seem to stabilize and reaches 64MB.

Either the test is a bad test and it should be removed or v16 has a different behavior that needs to be understood or there is a memory leak that appears in v16.

ideas are welcome

After reading process.memoryUsage() documentation it appears that
v13.9.0, v12.17.0 | Added arrayBuffers to the returned object.

arrayBuffers refers to memory allocated for ArrayBuffers and SharedArrayBuffers, including all Node.js Buffers. This is also included in the external value. When Node.js is used as an embedded library, this value may be 0 because allocations for ArrayBuffers may not be tracked in that case.

So it looks like this is what we want to track in the test instead of external when available.

the arrayBuffers stays under an acceptable limit for the test.
the external value goes to more high values, but it is interesting to note that after a 15s wait, it goes to nearly zero. so I suppose we are playing cat&mouse with the gc.

Since what we want to observe is that the memory dedicated to the buffers coming from postgres stays under the total size of the bytea, I consider that the test is now fixed.