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

Outbound NormalResponse optimizations #10318

Conversation

pveentjer
Copy link
Contributor

@pveentjer pveentjer commented Apr 12, 2017

This PR contains the following optimizations

  • for an operation that doesn't require backup acks (e.g. map.get or a map.put with async backup_ the NormalResponse instance is skipped (less litter)
  • if the response is data, the intermediate copy of the data into a ByteArrayObjectDataOutput is skipped. A byte array with the right size to store the whole response is created and the data is copied into this byte-array directly. So we get a packet-bytearray with a single copy of data instead of multiple copies.

This PR is native-memory friendly; it doesn't force the NativeMemoryData to create a copy onheap.

This is a follow up PR for
#10317

There is no change in the data that goes over the wire. So there will not be any minor version incompatibilities.

fix #10285

@pveentjer pveentjer added this to the 3.9 milestone Apr 12, 2017
@pveentjer pveentjer changed the title Outbound normalresponse optimizations Outbound NormalResponse optimizations Apr 12, 2017
@pveentjer pveentjer force-pushed the v3.9/performance/outbound-normalresponse-optimizations branch from f446c89 to a8b0887 Compare April 12, 2017 07:11
@pveentjer pveentjer force-pushed the v3.9/performance/outbound-normalresponse-optimizations branch from e920ce6 to 7533843 Compare April 12, 2017 08:32
@pveentjer
Copy link
Contributor Author

run-lab-run

@pveentjer pveentjer force-pushed the v3.9/performance/outbound-normalresponse-optimizations branch 2 times, most recently from 96be2f1 to 25fbe92 Compare April 12, 2017 11:01
Copy link
Contributor

@mmedenjak mmedenjak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some comments with duplicating the serialization

* But if you want to serialize an object to a byte-array and don't care for the Data partition-hash, the hash can be
* disabled.
*/
byte[] toBytes(Object obj, int leftPadding, boolean insertPartitionHash);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for the method and javadoc cleanup

}

Packet toNormalResponsePacket(long callId, int backupAcks, boolean urgent, Object value) {
byte[] bytes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So now the NormalResponse#writeData should not be called? Can we add some note or comment that we have this custom serialization? Can it throw an exception?
I like the optimisation, I'm just worrying that someone forgets that we duplicate the logic from the DataSerializableSerializer and EnterpriseDataSerializableSerializer here.
When someone makes some changes in those and forgets to change this serialization here, probably we will get failing tests (which is good).
Maybe just add some comments in the serializers there? Or make the NormalResponse not IDS and have it's serialization and deserialization fixed here?
Another idea - we move this into a new method on the internal serialization service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can still be called; I'm using them even to verify if the 'optimized' serialization does the same thing as serialization NormalResponse.

Eventually I would like to drop all the responses since they are not truly needed; but I tried this a few time and it leads to a lot of code change.

I like the optimisation, I'm just worrying that someone forgets that we duplicate the logic from the DataSerializableSerializer and EnterpriseDataSerializableSerializer here.

They can't be changed.. at least not in the 3.x timeline due to minor version compatibility.

Another idea - we move this into a new method on the internal serialization service?

I don't think we should get a dependency of something as specific as response into something generic as serialization. It would cause a cycle (tight coupling).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good that we have a test meaning that it will fail if someone tries to change the serialization format and forgets to change it in all places. Looking forward to moving the responses away from IDS and more internally.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we still remove them at all? They are part of 3.8 and with rolling upgrade we still have to support them (at least one minor version). Otherwise this should go on the 4.0 list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual data is going to remain the same. Only we don't need to have 'physical' response classes.

@pveentjer pveentjer force-pushed the v3.9/performance/outbound-normalresponse-optimizations branch 2 times, most recently from ae2138e to 15fcecf Compare April 12, 2017 12:33
@devOpsHazelcast
Copy link
Collaborator

@pveentjer pveentjer force-pushed the v3.9/performance/outbound-normalresponse-optimizations branch from 15fcecf to e458bd8 Compare April 12, 2017 12:46
@devOpsHazelcast
Copy link
Collaborator

Test PASSed.

//call id
writeLong(bytes, OFFSET_CALL_ID, callId, useBigEndian);
// urgent
bytes[OFFSET_URGENT] = (byte) (urgent ? 1 : 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is

@pveentjer pveentjer force-pushed the v3.9/performance/outbound-normalresponse-optimizations branch 2 times, most recently from 1309be9 to 0c1b91d Compare April 12, 2017 15:17
@devOpsHazelcast
Copy link
Collaborator

@pveentjer pveentjer force-pushed the v3.9/performance/outbound-normalresponse-optimizations branch from 0c1b91d to 98c2808 Compare April 12, 2017 15:26
@pveentjer
Copy link
Contributor Author

run-lab-run

@devOpsHazelcast
Copy link
Collaborator

Skips the NormalResponse creation in case of responses for responses
that don't require a ack from a backup.

Most importantly: it also skips an intermediate copy of the heap/native-data
into a temporary serialization buffer and then into the packet. With this change
the data is immediately copied into the packet-bytes.

This pr is nativememorydata friendly; it doesn't cause unwanted call to toByteArray.
@pveentjer pveentjer force-pushed the v3.9/performance/outbound-normalresponse-optimizations branch from 98c2808 to c687fac Compare April 12, 2017 16:13
@pveentjer
Copy link
Contributor Author

run-lab-run

@devOpsHazelcast
Copy link
Collaborator

Test PASSed.

@pveentjer
Copy link
Contributor Author

verify

@devOpsHazelcast
Copy link
Collaborator

devOpsHazelcast commented Apr 13, 2017

Test FAILed.

Unsupported major.minor version 51.0. You seem to have something in the build, which requires a newer Java version!
Indication 1 

@pveentjer
Copy link
Contributor Author

run-lab-run

@devOpsHazelcast
Copy link
Collaborator

Test PASSed.

@pveentjer pveentjer merged commit cfc1bcf into hazelcast:master Apr 13, 2017
@pveentjer pveentjer deleted the v3.9/performance/outbound-normalresponse-optimizations branch April 13, 2017 15:55
@mmedenjak mmedenjak added the Source: Internal PR or issue was opened by an employee label Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sending responses unwanted copying
4 participants