temporalio / temporalio/temporal

Better memory management for zap logger

Open
#3,543 0 comments 0 reactions 1 assignee View on GitHub

@yiminc is already working on this.

Since Nov 15, 2022.

enhancement
Dominant language
Go
Stars
23.2k
Forks
1.9k
Avg merge
2d 8h
Merged PRs (30d)
228

Description

Is your feature request related to a problem? Please describe.
The zap framework can consume an unbounded amount of memory, and often consumes more memory than it "needs to" due to naive use of sync.Pool.

For context, see this golang issue for a discussion of best (and worst!) practices around sync.Pool. Zap follows the bad practice of putting variable-sized buffers in its pool.

I've seen this cause bad behavior in temporal when it is frequently logging small lines but infrequently logging large lines. This pattern leads to an unnecessarily large zap buffer pool (in practice, I've seen up to 2.5gb). The golang issue discusses this scenario specifically here.

Describe the solution you'd like
See below - it's nothing but alternatives!

Describe alternatives you've considered
There's a lot we could do about this. Off the top of my head:

  • Dedup recent logs with long lines (e.g. ones with stack traces)
  • Commit any/several of the suggestions from the golang issue to zap:
    • Sometimes don't return large buffers to the pool.
    • Use a tiered pool (small vs. large).
    • Implement a real upper bound on pool size (and don't return buffers over that bound to the pool).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.