Azure / azure-cosmosdb-java

Java Async SDK for SQL API of Azure Cosmos DB
MIT License
54 stars 61 forks source link

memory improvements #230

Closed moderakh closed 5 years ago

moderakh commented 5 years ago

This PR Includes the following memory improvements. To review it is easier to review the commit per improvement:

(The following numbers are based on running benchmark tool on 16cpu core Linux VM with ReadThroughput workload and 4000 as degree of concurrency.)

1) when reading from network wire (through netty ByteBuf) we used to copy data once to ByteArrayOutputStream and from that we created String. Later ByteArrayOutputStream will get garbage collected, on high load this can lead to GCing 20-30% unnecessary data. The improvement is to pool the buffers: https://github.com/Azure/azure-cosmosdb-java/pull/230/commits/077d2ce24001726a5cb4399fbc8dbc187cdcec7e

2) we were deserializing replica physicalAddress in the AddressSelector to URI per request, we can cache the parsed URI form of the replica physical Address, also in the HttpTransportClient we were using URI for constructing paths which consumes more memory comparing to pure String. This somewhat contributed 5-10% memory which gets GCed: https://github.com/Azure/azure-cosmosdb-java/pull/230/commits/bd888d506998f93757eeef19a74da13350e537b6

3) we were decoding/encoding UUID to String unnecessarily. 2% memory improvement: https://github.com/Azure/azure-cosmosdb-java/pull/230/commits/d62a1aa208814d0e787fd37a74e2b682c954f4d7

4) in auth token generation we are using StringBuilder which grows (it copies data on each grow) as we append to it. This is improved by preserving memory 1-2% memory improvement: https://github.com/Azure/azure-cosmosdb-java/pull/230/commits/c8fc483569bc2ea930ef462d92ded43044b95e23

moderakh commented 5 years ago

/AzurePipelines run

azure-pipelines[bot] commented 5 years ago
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.
moderakh commented 5 years ago

/AzurePipelines run

azure-pipelines[bot] commented 5 years ago
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.
moderakh commented 5 years ago

/AzurePipelines run

azure-pipelines[bot] commented 5 years ago
Azure Pipelines could not run because the pipeline triggers exclude this branch/path.