-
Notifications
You must be signed in to change notification settings - Fork 625
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
Send fix message before logging it #36
base: master
Are you sure you want to change the base?
Conversation
Do not wait for the logger to perform its task before sending a message. Avoid printing the fix message to send two time in case of error (no responder). Removed the synchronization as it is contention prone, and not really needed : it should not really prevent synch issue with either setResponder(...) or disconnect(...) methods.
I added the volatile keyword. |
A lock has a potential of causing a context switch while a volatile doesn't, a lock is at least twice expensive than a volatile counterpart, specially for only reading the value Edit: But yeah, for most systems it will be a micro-optimization TBH. |
I know that the value can change between reads, I thought you would figure I meant only the whole if-then-else section:
And don't worry about the try, the compiler will optimize that out, also the != is first because the option to be more probable or the one that matters will be faster if it is treated 1st, have you measured performance with JMH? If so try my theory and you will see, don't guess, measure, measure. |
A context switch may happens at anytime because of interrupts and others potential jvm gc stop the world barriers. And even without theses events the value may be updated betweens two reads.
|
Oh yes, I agree
|
A context switch might happen for many reasons, specially the ones caused by the CPU scheduler but why should we add up to it? If we can avoid it by coding properly, I don't mean pre-optimize but sometimes it is obvious and trivial the use of atomic modifiers vs synchronization, and in this particular case it is trivial and obvious, well; except for the part of caching the value in every method that uses it (final Responder responder = this.responder) |
Try |
G1 and CMS are bad for low latency. The best we can have on hotspot is parrallel GC, with only minor collections.
|
Do you know that as a fact? G1GC is both parallel and concurrent. It is an active GC with the lowest time on stop world pauses, I have used it for few years now with Java 7 and up and I think is the best to avoid pauses, consistency > low latency even for low latency applications, if you have a chance of pausing for 1 or 2 secs then that is worse than possibly adding 1ms from time to time. |
by consistency I'm also referring to predictability, other GC algorithms are unpredictable making them bad for low latency where your highest time has to be less than X ms, that's where G1GC excels. |
@charlesbr1 @guidomedina G1/CMS/etc all have Stop the World young generation collections. The only collector with a concurrent young generation collector is C4 which is part of the Zing VM. It is in wide use in finance and other industries where predictable and low latencies are required. |
When you only have minor GC, they may be very predictable depending on your application, something like one pause every n minutes.
|
@nitsan : Sure, I said I was talking about hotspot. Btw, I love your work ;)
|
@guidomedina : I hadn't the code below my eyes, but you're changing the original external behaviour this way. Your logged message will be different when responder is null. |
better testing != null
@guidomedina wasn't clear on my cellphone, check != null is better I agree; I updated. |
Only updated the "boolean send(String messageString)" method.
Do not wait for the logger to perform its task before sending a message.
-> As a side effect, the logged fix message may now appears after other messages from the network stack.
Avoid printing the fix message to send two time in case of error (no responder).
Removed the synchronization as it is contention prone, and not really needed : it should not really prevent synch issue with either setResponder(...) or disconnect(...) methods.