-
Notifications
You must be signed in to change notification settings - Fork 92
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
proposed fix for #707 #708
Conversation
OK, @Sanne, @DavideD, @stuartwdouglas, WDYT of this? Obviously I have not tested it. |
I think we need good tests for this area, not least to check how this behaves when the consumer rate is higher than our ability to produce new ids. |
make sure that queued requests use the right session and entity args
Well, yeah, clearly. The problem is that we have precisely no tests for concurrent operation in the HR project, and I'm not clear even on the right way to write them. |
(I force-pushed to remove the useless |
Looks good, but if we have n consumers waiting maybe we should make sure we request at least n IDs? At the moment by default it is one at a time, so this is basically a global lock in terms of persist performance. |
Well the assumption I made was that you always choose a big enough block size that you "rarely" need to request a new block. If that's true, then I think having more requests waiting than the size of the block is an extremely low-probability event. On the other hand, what I realized earlier was that, ooops, what about people who don't want blocks, and set the block size to 1? We should actually be bypassing all this logic entirely in that case, and we don't. Not quite sure how I overlooked that. |
Also, at the time we request an hi value, we have zero consumers waiting. |
Well, hrm, actually I supposed it's not entirely clear what the best behavior here is. For sequences, yes, I think the right thing to do is not wait for concurrent requests to complete. For table generation it's not so clear, however. |
related to discussion around hibernate#707 This seems right for sequences. I'm not sure about tables though.
//special case where we're not using blocking at all | ||
return nextHiValue(session); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stuartwdouglas WDYT?
FWIW I had written a POC about a year ago to have such an optimizer, which would tune the page sized in an "adaptative" way. I abandoned it as I needed to learn how to test such things with vertx and never had much time - but it sounds like conceptually you might want to revive the idea. |
I mean in principle it would not be at all hard to increase the block size if we find ourselves requesting too many new blocks. Not hard at all. |
Right - and there's several other smart things one can easily do in the reactive model, such as we could already trigger a block allocation before the last available ID has been handed out to clients. So by observing the rate at which IDs are being consumed and the time it takes for block allocation tasks to complete it should be possible to:
One caveat of using dynamically allocated block sizes might be fragmentation; if there's multiple application nodes they still need to use a consistent strategy - should not be a problem when it's based on sequences (atomic) but if it's backed by some of the other models (table?) this is probably not a good idea. |
@stuartwdouglas can you do us a favor and test this patch in the context of the Quarkus issue? |
I think I have an idea, I will start prototyping something |
This works now, instead of doing a couple of requests then hanging it can now handle 3.5k inserts per second (this is not tuned in any way, it could probably do a lot more if I messed with some settings). |
Thanks 🙏 So perhaps it's worth doing a release just to fix this one thing. Thoughts? |
I think so, its a pretty bad bug. |
Actually I just realized that I am only testing the block size == 1 path, how do I configure a larger block size to test the other code path? |
With the |
Yes, we should release it. I will work on adding some more tests for the id generation but considering that @stuartwdouglas already tested on quarkus and that our current test suite works, releasing this version seems an important improvement for a release. |
It has been more than 10 years since I last actually 'used' JPA rather than just dealing with integration stuff. So it looks like the quickstart sets allocationSize = 1 for some reason, if you remove it then performance increases, but we get the occasional PK violation:
Looking at the logs some entities are being given the same PK. |
is this with a sequence generator or a table generator? |
|
Well that's very strange. Can you tell if it's because they are assigned (a) dupe hi values or (b) dupe lo values? |
I mean:
So ... another silly logical error in my code?? |
The id's in the errors are a long way apart, e.g: So it's not allocating duplicate blocks. |
They all seem to end in '1' |
Yup it's that, actually. Hold tight I will push a fix. |
wait, all the ids, or just all the dupe ids? |
No, excuse me. What I thought was wrong is actually fine. |
No, you mean the ones in the errors. So by the looks, they're all the "second id generated after fetching a new hi value". |
No, wait I guess you have |
I had to step away and have dinner, but my guess is something to do with
reentrant calls, so the sync block doesn't help. I can't see how though.
…On Fri, 16 Apr 2021, 8:07 pm Gavin King, ***@***.***> wrote:
they're all the "second id generated after fetching a new hi value".
No, wait I guess you have initialValue=1, the default, so they're the
*first* id's in their respective blocks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#708 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQG65CYQTOC7W5FYSN7CLTJAD7DANCNFSM427HLVCA>
.
|
Do you think it could be an out-of-order execution thing?? Like, Or am I trying to make this too complicated again? |
I mean, would moving the line |
Bugger, turns out this was user error. I forgot to clean before running quarkus:dev so it had cached the old maven dependencies, so it was not picking up the new version. It looks like this was a problem with the old version when the block size was larger than 1. Sorry for the noise. |
No problem. So how does it perform? |
Comparatively way better, 13,429 inserts per sec. This is no no way a proper benchmark, it's only using 2 threads and 10 connections. |
Alright. So that sounds good. Shall I merge this? |
Sounds good to me |
I've released it and sent a PR for quarkus: quarkusio/quarkus#16588 |
Thanks a lot @stuartwdouglas |
Make sure that queued requests use the right
session
andentity
args.