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
[FLINK-35215][core] Fix the bug when Kryo serialize length is 0 #24717
[FLINK-35215][core] Fix the bug when Kryo serialize length is 0 #24717
Conversation
This reverts commit 3977982.
Not to block this, just curious do you know why FLINK-34954 affects performance? |
while (bytesRead < count) { | ||
while (true) { | ||
c = inputStream.read(bytes, offset + bytesRead, count - bytesRead); | ||
|
||
if (c == -1) { | ||
throw new KryoException(new EOFException("No more bytes left.")); | ||
} | ||
|
||
bytesRead += c; | ||
|
||
if (bytesRead == count) { |
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.
Not to block this, just curious do you know why FLINK-34954 affects performance?
Hi @reswqa , I'm not very sure the reason. But I guess:
- For non-empty data, let us assume
inputStream.read
will be called once.- Before FLINK-34954, we only check
bytesRead == count
once. - After FLINK-34954, we call
bytesRead < count
twice.
- Before FLINK-34954, we only check
- Also, I'm not sure whether FLINK-34954 breaks any JIT optimization.
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.
Thanks! Yes, I don't know the details also, but it's possible that JIT optimizations were affected.
Re-implement to avoid the performance regression
f09de06
to
ba2740f
Compare
if (count == 0) { | ||
return; | ||
} | ||
|
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.
This if (count == 0) {
is alternative change for FLINK-34954, I ran the demo that provided in FLINK-34954, it works well. So I think the change is fine.
Also, I ran the benchmark, the performance of serializerKryo and serializerKryoWithoutRegistration are recovered.
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.
Hi @dannycranmer , this issue is the blocker of Flink 1.20, and you are the reviewer of #24586, would you mind reviewing this PR as well? thanks in advance.
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.
@1996fanrui Can you add the demo from FLINK-34954 as a test?
I'm leaving in 2 days for a 4+ month backpack trip (hiking the PCT), otherwise what I'd do is try to hook up a test that uses JMH to accurately assess the impact of the change. To respond to the particular comment on why performance changed:
The overhead of two comparisons, versus even one call to
If a JIT optimization would result in skipping calls to The one thing I see is in the change to |
Wow, have a nice trip!
As I said before, I'm not sure the reason, and both of them are my guess.
Sorry, I didn't fully understand this sentence. Do you mean skip the |
Sorry for the confusing sentence. I meant that skipping the |
Thanks for the quick clarification! Yes, my change only adds a simple check |
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.
I'm leaving in 2 days for a 4+ month backpack trip (hiking the PCT), otherwise what I'd do is try to hook up a test that uses JMH to accurately assess the impact of the change. To respond to the particular comment on why performance changed:
we call bytesRead < count twice
The overhead of two comparisons, versus even one call to inputStream.read, should be miniscule.
I agree that some explanation is missing here. While I would be also curious to understand all of this better, I'm fine if this is merged as is. In the absence of a better performance indicator, I would relay on our imperfect benchmarking results, which suggests we should merge this one over the current master.
We can also continue investigation asynchronously after merging this fix if someone is interested in doing that.
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.
Thanks @pnowojski for the comment and review!
Let me merge this PR first, and I will follow the benchmark in the following days.
What is the purpose of the change
The performance of serializerKryo and serializerKryoWithoutRegistration are regressed, I checked recent commits, and found FLINK-34954 changed related logic.
Brief change log