Skip to content

GH-40040: [C++][Gandiva] Make Gandiva's default cache size to be 5000 for object code cache#40041

Merged
pitrou merged 1 commit intoapache:mainfrom
niyue:feature/gdv-cache-size
Feb 14, 2024
Merged

GH-40040: [C++][Gandiva] Make Gandiva's default cache size to be 5000 for object code cache#40041
pitrou merged 1 commit intoapache:mainfrom
niyue:feature/gdv-cache-size

Conversation

@niyue
Copy link
Copy Markdown
Contributor

@niyue niyue commented Feb 12, 2024

Rationale for this change

Gandiva's default cache is object code cache, however, the default cache size is still the old value for LLVM module based cache, which is too small.

More details about the GANDIVA_ENABLE_OBJECT_CODE_CACHE flag can be found in GH-40040

What changes are included in this PR?

Remove the unused GANDIVA_ENABLE_OBJECT_CODE_CACHE flag and make the default cache size to be 500000 for object code cache.

Are these changes tested?

No

Are there any user-facing changes?

Yes, default cache size will be changed from 500 to 500000, and it may help the default deployment's performance.

@github-actions
Copy link
Copy Markdown

⚠️ GitHub issue #40040 has been automatically assigned in GitHub to PR creator.

pitrou
pitrou previously approved these changes Feb 12, 2024
Copy link
Copy Markdown
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like an obvious fix, thank you

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Feb 12, 2024
@pitrou pitrou self-requested a review February 12, 2024 16:55
@pitrou pitrou dismissed their stale review February 12, 2024 16:56

Taking a closer look at the size calculation, this may not be desirable.

Copy link
Copy Markdown
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the earlier review. It seems this PR misunderstands the cache size. 500 cache entries is actually not that bad.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a problem here: what is the unit? The large number seems to imply this is expressed in bytes.
However, the size will actually be interpreted as the number of stored entries (it's passed to LruCache which in turn compares it to std::unordered_map::size).

It would probably be beneficial to cap the number of bytes and not the number of entries, but this is not what this PR does. 500000 cache entries may easily add up to hundreds of megabytes of RAM.

Copy link
Copy Markdown
Contributor Author

@niyue niyue Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, the unit in question pertains to the number of entries rather than bytes, but there's no misunderstanding of the cache size and the original value of 500 was also defined in terms of the number of entries. This PR aims to address an oversight by removing a previously missed flag.

This link [1] has more data about module cache vs. object code cache in Gandiva, and in the limited expressions tested, the memory is down to 0.8%~6% after using object code cache.

The current default value 500 is likely too small in production, and it will probably only use 8MB of memory using the stats in link [1], but you are right it seems 500000 is indeed too large (I have no idea how it was defined this way and I should do more calculation for it). According to the stats in link [1], when using module cache, it will probably take 750MB memory for 500 entries.

Other initiatives [2] have attempted to enhance the cache eviction algorithm, but such attempts were reversed due to other issues [3]. I've previously reviewed these efforts and believe I have distinct ideas for advancing Gandiva's cache. I plan to propose a PR if I fully understand the workflow. To avoid complicating this PR, my goal is solely to refine the default value. Would it be acceptable to adopt a more conservative default value, such as 5000/10000? Thanks.

[1] #11193 (comment)
[2] #10465
[3] #11957

@pitrou
Copy link
Copy Markdown
Member

pitrou commented Feb 13, 2024

cc @js8544

@js8544
Copy link
Copy Markdown
Contributor

js8544 commented Feb 13, 2024

Happy Chinese New Year!

@pitrou I think this PR is to fix the regression introduced in #12742 rather than a feature. #12742 sets GANDIVA_ENABLE_OBJECT_CODE_CACHE default to true but forget to change the default cache size. @niyue Is my understanding correct?

However I do agree that we can further investigate the size limit of the cache. 500000 objects should require too much memory. Suppose one expression takes 1KB (my wild guess), that would be 500MB.

@pitrou
Copy link
Copy Markdown
Member

pitrou commented Feb 13, 2024 via email

@niyue
Copy link
Copy Markdown
Contributor Author

niyue commented Feb 14, 2024

#12742 sets GANDIVA_ENABLE_OBJECT_CODE_CACHE default to true but forget to change the default cache size. @niyue Is my understanding correct?

Happy Chinese New Year!
That's correct. I didn't explicitly mentioned this in this PR description, but it is described in #40040 issue description.

@niyue niyue force-pushed the feature/gdv-cache-size branch from cc9cc6d to 201dcf8 Compare February 14, 2024 02:17
… address the previous oversight after switching to object code cache.
@niyue niyue force-pushed the feature/gdv-cache-size branch from 201dcf8 to 41eaf6a Compare February 14, 2024 02:24
@niyue niyue changed the title GH-40040: [C++][Gandiva] Make Gandiva's default cache size to be 500000 for object code cache GH-40040: [C++][Gandiva] Make Gandiva's default cache size to be 5000 for object code cache Feb 14, 2024
@niyue
Copy link
Copy Markdown
Contributor Author

niyue commented Feb 14, 2024

@js8544 @pitrou
Thanks for the review, and I updated the default value and the PR title to be 5000 now.

Copy link
Copy Markdown
Contributor

@js8544 js8544 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 LGTM

@pitrou pitrou merged commit 967831b into apache:main Feb 14, 2024
@pitrou pitrou removed the awaiting committer review Awaiting committer review label Feb 14, 2024
@github-actions github-actions bot added the awaiting committer review Awaiting committer review label Feb 14, 2024
@pitrou
Copy link
Copy Markdown
Member

pitrou commented Feb 14, 2024

Thank you @niyue !

@conbench-apache-arrow
Copy link
Copy Markdown

After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 967831b.

There was 1 benchmark result with an error:

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 1 possible false positive for unstable benchmarks that are known to sometimes produce them.

dgreiss pushed a commit to dgreiss/arrow that referenced this pull request Feb 19, 2024
…e 5000 for object code cache (apache#40041)

### Rationale for this change
Gandiva's default cache is object code cache, however, the default cache size is still the old value for LLVM module based cache, which is too small. 

More details about the `GANDIVA_ENABLE_OBJECT_CODE_CACHE` flag can be found in apacheGH-40040

### What changes are included in this PR?
Remove the unused `GANDIVA_ENABLE_OBJECT_CODE_CACHE` flag and make the default cache size to be `500000` for object code cache.

### Are these changes tested?
No

### Are there any user-facing changes?
Yes, default cache size will be changed from 500 to 500000, and it may help the default deployment's performance.
* Closes: apache#40040

Authored-by: Yue Ni <niyue.com@gmail.com>
Signed-off-by: Antoine Pitrou <antoine@python.org>
@dmitry-chirkov-dremio
Copy link
Copy Markdown
Contributor

How would one go about configuring the cache size via something other than environment variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][Gandiva] default cache size is incorrect and too small

4 participants