Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception uses as flow control #170

Closed
fbacchella opened this issue Jan 25, 2021 · 2 comments
Closed

Exception uses as flow control #170

fbacchella opened this issue Jan 25, 2021 · 2 comments
Assignees
Milestone

Comments

@fbacchella
Copy link

I’m using cache2k 2.0.0.Final.

In org.cache2k.processor.EntryProcessor, I see the code:

        try {
          R result = processor.process(mutableEntry);
          c.result(result);
        } catch (WantsDataRestartException rs) {
          c.wantData();
          return;
        } catch (NeedsLockRestartException ex) {
          needsLock = true;
          c.wantData();
          return;
        } catch (Throwable t) {
          c.failure(new EntryProcessingException(t));
          return;
        }

So it's code were exception are used as flow control. But it's usually a bad idea, see https://shipilev.net/blog/2014/exceptional-performance/ for a deep analysis of that.

For example, when generating flamegraph for some of my code, I get the following result:

flamegraph

Most of the time is spent filling in the stack trace.

The code that generate this stack can be found at NettyNameResolver.java

Performance could be increased I think if both WantsDataRestartException and NeedsLockRestartException (and perhaps other) were static and not saving the stack.

This constructor can be used for that:

protected Exception(String message,
                    Throwable cause,
                    boolean enableSuppression,
                    boolean writableStackTrace)

If writableStackTrace is set to false, the stack trace is not saved.

@cruftex cruftex added this to the v2.2 milestone Jan 26, 2021
@cruftex cruftex self-assigned this Jan 26, 2021
@cruftex
Copy link
Member

cruftex commented Jan 26, 2021

@fbacchella thanks for the analysis. That looks like a quick win. I will put an improvement in the next release.

I also looked at your code. Using JCache you need to do per entry TTL by yourself. Cache2k would support this directly and do an efficient expiry via timer wheel and scheduler.

@cruftex
Copy link
Member

cruftex commented Mar 26, 2021

I implemented your suggestion and released an alpha update for verification. Thanks for reporting!
https://github.com/cache2k/cache2k/releases/tag/v2.1.2.Alpha

@cruftex cruftex closed this as completed Mar 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy