LakshSingla opened a new pull request #12001:
URL: https://github.com/apache/druid/pull/12001


   ### Description
   
   `DruidSchema` consists of a concurrent HashMap of `DataSource` -> `Segement` 
-> `AvailableSegmentMetadata`. `AvailableSegmentMetadata` contains 
`RowSignature` of the segment, and for each segment, a new object is getting 
created. RowSignature is an immutable class, and hence it can be interned, and 
this can lead to huge savings of memory being used in broker, since a lot of 
the segments of a table would potentially have same RowSignature.
   
   Following are some heap dumps of the broker attached for some experiments. 
The data being ingested is the quickstart `wikipedia` data, but the secondary 
partition is dynamic with 1 max row per segment, to generate a lot of segments 
which the `DruidSchema` would have to cache. Also, the configuration used is 
`start-single-server-small`. 
   For the normal testing `apache-druid-0.22.0` was used while the patch was 
tested on top of the `master` branch (shouldn't cause much difference).
   
   1.
   No additional columns were appended to the existing columns of the wiki data.
   #### Non Interned
   ![Screenshot 2021-11-30 at 1 19 07 
AM](https://user-images.githubusercontent.com/30999375/143933629-63366e17-1288-4ba7-8ba7-8eab811443c2.png)
   
   ![Screenshot 2021-11-30 at 1 19 45 
AM](https://user-images.githubusercontent.com/30999375/143933700-c4a88d0e-64f5-4c2b-b970-b355378c3569.png)
   
   #### Interned
   ![Screenshot 2021-11-30 at 1 20 04 
AM](https://user-images.githubusercontent.com/30999375/143933765-b888b5fa-92ba-4dea-a9c0-850e5dab914a.png)
   
   ![Screenshot 2021-11-30 at 1 20 19 
AM](https://user-images.githubusercontent.com/30999375/143933804-26b362d8-a091-4f71-a2d6-4e914355e01b.png)
   
   2.
   51 addititonal columns were appended to the original columns with names 
"random-#" to increase the memory footprint of the RowSignature.
   #### Non Interned
   ![Screenshot 2021-11-30 at 1 20 42 
AM](https://user-images.githubusercontent.com/30999375/143933860-78c483d5-7aef-44ba-959c-93162c2f8f00.png)
   
   ![Screenshot 2021-11-30 at 1 20 54 
AM](https://user-images.githubusercontent.com/30999375/143933892-035c6023-5365-465f-afcc-500061c3bedb.png)
    
   #### Interned
   
   ![Screenshot 2021-11-30 at 1 21 15 
AM](https://user-images.githubusercontent.com/30999375/143933921-4b14e2c3-abbc-497b-9b13-9031d5ed26ba.png)
   
   ![Screenshot 2021-11-30 at 1 21 33 
AM](https://user-images.githubusercontent.com/30999375/143933941-986d69c4-2e0b-40a9-8763-b06ec2cd767a.png)
   
   This change precomputes the hash of the RowSignature, since its an immutable 
object, as well as uses an interner in the DruidSchema to generate the 
AvailableSegmentMetadata objects.
   
   Benchmark was added to see the effect of interning on the time required to 
create the DruidSchema object. It can be removed in the end, if not required.
   
   <hr>
   
   ##### Key changed/added classes in this PR
    * `DruidSchema` - Intern the RowSignature
    * `RowSignature` - Precompute the hash function
   
   <hr>
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not 
all of these items apply to every PR. Remove the items which are not done or 
not relevant to the PR. None of the items from the checklist below are strictly 
necessary, but it would be very helpful if you at least self-review the PR. -->
   
   This PR has:
   - [x] been self-reviewed.
      - [ ] using the [concurrency 
checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md)
 (Remove this item if the PR doesn't have any relation to concurrency.)
   - [ ] added documentation for new or modified features or behaviors.
   - [x] added Javadocs for most classes and all non-trivial methods. Linked 
related entities via Javadoc links.
   - [ ] added or updated version, license, or notice information in 
[licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
   - [x] added comments explaining the "why" and the intent of the code 
wherever would not be obvious for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, 
ensuring the threshold for [code 
coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md)
 is met.
   - [ ] added integration tests.
   - [x] been tested in a test Druid cluster.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to