Description
I'm working with a client that runs a simple Node process to consume messages off of a queue (NSQ) and send them to a downstream API (over TLS). We are using superagent as a HTTP client. Some of the processes we are running were using over 1.8GB of memory.
After a long investigation we discovered that the memory bloat was because transparent huge pages were enabled. Disabling transparent huge pages immediately took the memory usage down to about 150MB per process. This is most dramatically visualized here:
We're unsure exactly what mechanism was responsible for allocating so much memory, but took a core dump and noticed about 160,000 copies of the certificate list in memory - specifically an engineer ran strings | grep -i verisign
and found that string 160,000 times. We suspect it's related to TLS negotiation or zlib or both.
We were running Node v6.9.2. The symptoms were extremely high (but not growing) memory usage that is off the Node heap - we ran node-heapdump
on the process and we were only able to account for about 18MB of 1.8GB. Checking /proc/<pid>/smaps
revealed that most of the memory was in AnonHugePages.
I'm mostly posting because there appear to be no Node-specific resources that point to transparent huge pages as a potential problem for memory management with Node. A Google search for "node transparent huge pages" yields nothing suggesting it might be a problem for Node users.
Several databases warn about the consequences of enabling transparent huge pages:
- TokuMX https://www.percona.com/blog/2014/07/23/why-tokudb-hates-transparent-hugepages/
- Redis https://www.digitalocean.com/company/blog/transparent-huge-pages-and-alternative-memory-allocators/
- Oracle https://blogs.oracle.com/linux/entry/performance_issues_with_transparent_huge
- MongoDB https://docs.mongodb.com/manual/tutorial/transparent-huge-pages/