You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2022/10/12 19:45:23 UTC

[GitHub] [druid] zachjsh opened a new pull request, #13219: Improve global-cached-lookups metric reporting

zachjsh opened a new pull request, #13219:
URL: https://github.com/apache/druid/pull/13219

   It was found that the `namespace/cache/heapSizeInBytes` metric that tracks the total heap size in bytes of all lookup caches loaded on a service instance was being under reported. We were not accounting for the memory overhead of the String object, which I've found in testing to be ~40 bytes. While this overhead may be java version dependent, it should not vary much, and accounting for this provides a better estimate. Also fixed some logging, and reading bytes from the JDBI result set a little more efficient by saving hash table lookups.
   
   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.
   - [ ] a release note entry in the PR description.
   - [ ] 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)
   - [ ] 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.
   - [ ] 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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] kfaraz commented on a diff in pull request #13219: Improve global-cached-lookups metric reporting

Posted by GitBox <gi...@apache.org>.
kfaraz commented on code in PR #13219:
URL: https://github.com/apache/druid/pull/13219#discussion_r994041387


##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/data/input/MapPopulator.java:
##########
@@ -245,7 +245,8 @@ static long getByteLengthOfObject(@Nullable Object o)
   {
     if (null != o) {
       if (o.getClass().getName().equals(STRING_CLASS_NAME)) {
-        return ((String) (o)).length();
+        // Each String object has ~40 bytes of overhead
+        return ((long) ((String) (o)).length() * Character.BYTES) + 40;

Review Comment:
   You could also consider doing this instead:
   https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/StringDimensionDictionary.java#L41-L47



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] abhishekagarwal87 commented on a diff in pull request #13219: Improve global-cached-lookups metric reporting

Posted by GitBox <gi...@apache.org>.
abhishekagarwal87 commented on code in PR #13219:
URL: https://github.com/apache/druid/pull/13219#discussion_r994291902


##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/data/input/MapPopulator.java:
##########
@@ -245,7 +245,8 @@ static long getByteLengthOfObject(@Nullable Object o)
   {
     if (null != o) {
       if (o.getClass().getName().equals(STRING_CLASS_NAME)) {
-        return ((String) (o)).length();
+        // Each String object has ~40 bytes of overhead
+        return ((long) ((String) (o)).length() * Character.BYTES) + 40;

Review Comment:
   it's better to use the same calculation and code. 
   @zachjsh - can you reuse the code? The common code can be placed in `StringUtils` class. 



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] kfaraz commented on a diff in pull request #13219: Improve global-cached-lookups metric reporting

Posted by GitBox <gi...@apache.org>.
kfaraz commented on code in PR #13219:
URL: https://github.com/apache/druid/pull/13219#discussion_r994041387


##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/data/input/MapPopulator.java:
##########
@@ -245,7 +245,8 @@ static long getByteLengthOfObject(@Nullable Object o)
   {
     if (null != o) {
       if (o.getClass().getName().equals(STRING_CLASS_NAME)) {
-        return ((String) (o)).length();
+        // Each String object has ~40 bytes of overhead
+        return ((long) ((String) (o)).length() * Character.BYTES) + 40;

Review Comment:
   You could also consider doing this instead:
   https://github.com/apache/druid/blob/346fbf133fa338fe0ccf76b5537eb1627f28a487/processing/src/main/java/org/apache/druid/segment/StringDimensionDictionary.java#L42



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] kfaraz commented on a diff in pull request #13219: Improve global-cached-lookups metric reporting

Posted by GitBox <gi...@apache.org>.
kfaraz commented on code in PR #13219:
URL: https://github.com/apache/druid/pull/13219#discussion_r994278022


##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/data/input/MapPopulator.java:
##########
@@ -245,7 +245,8 @@ static long getByteLengthOfObject(@Nullable Object o)
   {
     if (null != o) {
       if (o.getClass().getName().equals(STRING_CLASS_NAME)) {
-        return ((String) (o)).length();
+        // Each String object has ~40 bytes of overhead
+        return ((long) ((String) (o)).length() * Character.BYTES) + 40;

Review Comment:
   I think we can proceed with what you have. It's a difference of just 4 bytes (40 vs 44) per String anyway, and as you mention, it does depend on java version.



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] kfaraz commented on a diff in pull request #13219: Improve global-cached-lookups metric reporting

Posted by GitBox <gi...@apache.org>.
kfaraz commented on code in PR #13219:
URL: https://github.com/apache/druid/pull/13219#discussion_r994041387


##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/data/input/MapPopulator.java:
##########
@@ -245,7 +245,8 @@ static long getByteLengthOfObject(@Nullable Object o)
   {
     if (null != o) {
       if (o.getClass().getName().equals(STRING_CLASS_NAME)) {
-        return ((String) (o)).length();
+        // Each String object has ~40 bytes of overhead
+        return ((long) ((String) (o)).length() * Character.BYTES) + 40;

Review Comment:
   You could also consider doing this instead:
   https://github.com/apache/druid/blob/346fbf133fa338fe0ccf76b5537eb1627f28a487/processing/src/main/java/org/apache/druid/segment/StringDimensionDictionary.java#L41-L47



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] zachjsh merged pull request #13219: Improve global-cached-lookups metric reporting

Posted by GitBox <gi...@apache.org>.
zachjsh merged PR #13219:
URL: https://github.com/apache/druid/pull/13219


-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org


[GitHub] [druid] zachjsh commented on a diff in pull request #13219: Improve global-cached-lookups metric reporting

Posted by GitBox <gi...@apache.org>.
zachjsh commented on code in PR #13219:
URL: https://github.com/apache/druid/pull/13219#discussion_r994245240


##########
extensions-core/lookups-cached-global/src/main/java/org/apache/druid/data/input/MapPopulator.java:
##########
@@ -245,7 +245,8 @@ static long getByteLengthOfObject(@Nullable Object o)
   {
     if (null != o) {
       if (o.getClass().getName().equals(STRING_CLASS_NAME)) {
-        return ((String) (o)).length();
+        // Each String object has ~40 bytes of overhead
+        return ((long) ((String) (o)).length() * Character.BYTES) + 40;

Review Comment:
   Thanks for pointing this out! The I think depends on the particular version of java and beyond that the particular distribution of it. In my testing I found 40 bytes to be a good estimate for overhead. Sometimes I find that its a bit less. Will leave as is unless you feel strongly about changing.



-- 
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: commits-unsubscribe@druid.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org