FasterXML / jackson-core

Core part of Jackson that defines Streaming API as well as basic shared abstractions
Apache License 2.0
2.25k stars 773 forks source link

The JsonReyclerPools#LockFreePool object takes up a large amount of memory #1320

Closed zhanbei1 closed 2 months ago

zhanbei1 commented 2 months ago

Search before asking

Describe the bug

Using com. fasterxml. jackson. core: jackson-databind: 2.17.1 version. And use the following code:

private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper()
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS.mappedFeature())
.enable(JsonReadFeature.ALLOW_LEADING_ZEROS_FOR_NUMBERS.mappedFeature())
.enable(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS);

OBJECT_MAPPER operates on string or Json data.

But this is often my code OOM. Looking at the JVM memory, objects in old_gen keep growing and are hard to gC-drop.(JVM Heap is 2G)

The hprof file generated after OOM occurs, using visualVM: 2.1.8 version, carries on the analysis, discover com. fasterxml. jackson. core. util. JsonReyclerPools# LockFreePool object occupies a lot of memory, and there is some json string type.

截屏2024-07-06 01 49 00 截屏2024-07-06 01 27 42

May I ask what caused this? Did I use it wrong?

Version Information

jackson-databind:2.17.1

Reproduction

<-- Any of the following

  1. Brief code sample/snippet: include here in preformatted/code section
  2. Longer example stored somewhere else (diff repo, snippet), add a link
  3. Textual explanation: include here -->
    // Your code here

Expected behavior

No response

Additional context

No response

cowtowncoder commented 2 months ago

The VERY FIRST THING to try is the LATEST PATCH VERSION of minor version you have. This would be 2.16.2.

This is, in fact, something you should have already tried before filing an issue.

So please try that now.

But also -- just in case -- please double-check you know the exact version of jackson-core you have. Only Jackson 2.17.0 change the default pool to "lockFreePool".

Finally, I will move this issue to its proper place, jackson-core repository where Recycler Pools reside.

zhanbei1 commented 2 months ago

The VERY FIRST THING to try is the LATEST PATCH VERSION of minor version you have. This would be 2.16.2.

This is, in fact, something you should have already tried before filing an issue.

So please try that now.

But also -- just in case -- please double-check you know the exact version of jackson-core you have. Only Jackson 2.17.0 change the default pool to "lockFreePool".

Finally, I will move this issue to its proper place, jackson-core repository where Recycler Pools reside.

I'm very sorry, I just got the version number wrong, the version I used is 2.17.1, my comment has been updated. Find a similar issue:https://github.com/FasterXML/jackson-databind/issues/4500

It is not known if this issue has been fixed in a later version

cowtowncoder commented 2 months ago

Issue was indeed fixed by default change in 2.17.1 (as noted in the issue you mention); the problem did affect 2.17.0 (and only 2.17.0).

The only way LockFreePool would be used with 2.17.1 is if application code explicitly configured it to be used. So I would make sure that the version you use is 2.17.1 (or 2.17.2 which is being released today). Specifically jackson-core version: jackson-databind does not control RecyclerPool configuration in any way.

If problem seems to occur with jackson-core 2.17.1, also ensure that there is no configuration override to change the recycler pool to LockFreePool.

zhanbei1 commented 2 months ago

Issue was indeed fixed by default change in 2.17.1 (as noted in the issue you mention); the problem did affect 2.17.0 (and only 2.17.0).

The only way LockFreePool would be used with 2.17.1 is if application code explicitly configured it to be used. So I would make sure that the version you use is 2.17.1 (or 2.17.2 which is being released today). Specifically jackson-core version: jackson-databind does not control RecyclerPool configuration in any way.

If problem seems to occur with jackson-core 2.17.1, also ensure that there is no configuration override to change the recycler pool to LockFreePool.

Ok, I have understood. Thank you very much for your reply. And I'm going to close this Issue

cowtowncoder commented 2 months ago

Thank you @zhanbei1 ! I hope things resolve as expected, best of luck.