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

Is there a performance problem with the next(n) method? #482

Open
chenggwang opened this issue Aug 28, 2024 · 3 comments
Open

Is there a performance problem with the next(n) method? #482

chenggwang opened this issue Aug 28, 2024 · 3 comments

Comments

@chenggwang
Copy link

In the next(n) method we used long wrapPoint = nextSequence - bufferSize;wrapPoint > cachedGatingSequence in determining whether a wrap occurred or not.For example, in the following figure:
无标题
Let's say we've posted a round, at which point cursor=15 and cachedGatingSequence=1. The producer calls next(4) again; the pseudo-code logic looks like this:

nextSequence=19=15+4;
wrapPoint = 19-16=3;
wrapPoint> cachedGatingSequence(3>1);
parkNanos(1L);

but it is clear that there are already two positions that can be filled, but we have to wait for “C” and “D” to be consumed before we can post an event to fill. General machine 100 times the value of the simple assignment of about 1500-5000 nanoseconds, assuming that we next (200) read and write events are simple assignment operations, 100 events are consumed, there are still 100 events have not been consumed, at this time the wrap occurs, then it is not 1500-5000 times parkNanos (1L), this system switching is not 1500-5000 times parkNanos (1L), this system switching is not a good idea? ), is this system switching too consuming?On the contrary, if you use next(), then each time you judge for the next cursor position, you will wait for one consumption at most. So is it recommended to use the default next()? And next(n) hanging mechanism instead of simple parkNanos(1L), such as and n some kind of correlation, or to put the winding judgment to event fill to determine the sequence of each slot? (Of course, this change for the whole architecture is a big disruption)

@ocoanet
Copy link
Contributor

ocoanet commented Aug 29, 2024

A few thoughts:

  • A filled ring-buffer is an uncomfortable situation in the first place. The queueing will increase the event processing latency and the backpressure will probably negatively impact the producer performance. I am not sure it is worth optimizing batch publication for this scenario.
  • next(int n) is also used to claim a contiguous block of events. In this case, you cannot replace it by multiple calls to next().
  • Using next(int n) for performance is a good practice (even if you do not need contiguous events). If you fear to hit the ring-buffer capacity, you can simplify add a reasonable upper bound to n. "reasonable" is relative to you ring-buffer size of course.

@chenggwang
Copy link
Author

A few thoughts:

  • A filled ring-buffer is an uncomfortable situation in the first place. The queueing will increase the event processing latency and the backpressure will probably negatively impact the producer performance. I am not sure it is worth optimizing batch publication for this scenario.
  • next(int n) is also used to claim a contiguous block of events. In this case, you cannot replace it by multiple calls to next().
  • Using next(int n) for performance is a good practice (even if you do not need contiguous events). If you fear to hit the ring-buffer capacity, you can simplify add a reasonable upper bound to n. "reasonable" is relative to you ring-buffer size of course.

OK!@ocoanet Thank you for your thoughts! I brought this up because I wanted everyone to discuss it. All can understand this framework design details more deeply in the discussion.A small request, by the way.@Palmr By the way a small request, can you mark my issues as questions?

@Palmr
Copy link
Contributor

Palmr commented Sep 9, 2024

@swarren12 or @isolgpus will have to assist with changing issue types.

Earlier this year I left LMAX and therefore handed back my owner rights for this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants