You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/02/10 15:33:12 UTC

[GitHub] [spark] Myasuka opened a new pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Myasuka opened a new pull request #35480:
URL: https://github.com/apache/spark/pull/35480


   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   Correct the logic to measure the memory usage of RocksDB to include the memory used by block cache.
   
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   Current reported metrics of RocksDB memory usage is not correct.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   NO
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
   -->
   The information could refer to https://github.com/facebook/rocksdb/wiki/Memory-usage-in-RocksDB


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Myasuka commented on a change in pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
Myasuka commented on a change in pull request #35480:
URL: https://github.com/apache/spark/pull/35480#discussion_r804329368



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
##########
@@ -403,7 +404,7 @@ class RocksDB(
     RocksDBMetrics(
       numKeysOnLoadedVersion,
       numKeysOnWritingVersion,
-      readerMemUsage + memTableMemUsage,
+      readerMemUsage + memTableMemUsage + blockCacheUsage,

Review comment:
       > based on the doc, do we also need rocksdb.block-cache-pinned-usage?
   
   No, I don't think so, and I actually write my conclusion in original ticket SPARK-38178:
   `BTW, as the "block-cache-pinned-usage" is included in "block-cache-usage", we don't need to include the pinned usage.`
   
   Let's take a look at the RocksDB implementation:
   
   - [how methods handle the property query:](https://github.com/facebook/rocksdb/blob/073ac547391870f464fae324a19a6bc6a70188dc/db/internal_stats.cc#L545-L550)
   ~~~c++
     {DB::Properties::kBlockCacheUsage,
      {false, nullptr, &InternalStats::HandleBlockCacheUsage, nullptr,
       nullptr}},
     {DB::Properties::kBlockCachePinnedUsage,
      {false, nullptr, &InternalStats::HandleBlockCachePinnedUsage, nullptr,
       nullptr}},
   ~~~
   - And what will call for these two [handle methods](https://github.com/facebook/rocksdb/blob/073ac547391870f464fae324a19a6bc6a70188dc/db/internal_stats.cc#L1304-L1324):
   ~~~ c++
   bool InternalStats::HandleBlockCacheUsage(uint64_t* value, DBImpl* /*db*/,
                                             Version* /*version*/) {
     Cache* block_cache;
     bool ok = GetBlockCacheForStats(&block_cache);
     if (!ok) {
       return false;
     }
     *value = static_cast<uint64_t>(block_cache->GetUsage());
     return true;
   }
   
   bool InternalStats::HandleBlockCachePinnedUsage(uint64_t* value, DBImpl* /*db*/,
                                                   Version* /*version*/) {
     Cache* block_cache;
     bool ok = GetBlockCacheForStats(&block_cache);
     if (!ok) {
       return false;
     }
     *value = static_cast<uint64_t>(block_cache->GetPinnedUsage());
     return true;
   }
   ~~~
   
   - And then [the implementation](https://github.com/facebook/rocksdb/blob/073ac547391870f464fae324a19a6bc6a70188dc/cache/lru_cache.cc#L625-L634) of these two getters:
   ~~~ c++
   size_t LRUCacheShard::GetUsage() const {
     MutexLock l(&mutex_);
     return usage_;
   }
   
   size_t LRUCacheShard::GetPinnedUsage() const {
     MutexLock l(&mutex_);
     assert(usage_ >= lru_usage_);
     return usage_ - lru_usage_;
   }
   ~~~
   
   As you can see, the pinned usage is included in the block cache usage.




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #35480:
URL: https://github.com/apache/spark/pull/35480#discussion_r803928220



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
##########
@@ -403,7 +404,7 @@ class RocksDB(
     RocksDBMetrics(
       numKeysOnLoadedVersion,
       numKeysOnWritingVersion,
-      readerMemUsage + memTableMemUsage,
+      readerMemUsage + memTableMemUsage + blockCacheUsage,

Review comment:
       based on the doc, do we also need `rocksdb.block-cache-pinned-usage`?




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #35480:
URL: https://github.com/apache/spark/pull/35480#discussion_r803928220



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
##########
@@ -403,7 +404,7 @@ class RocksDB(
     RocksDBMetrics(
       numKeysOnLoadedVersion,
       numKeysOnWritingVersion,
-      readerMemUsage + memTableMemUsage,
+      readerMemUsage + memTableMemUsage + blockCacheUsage,

Review comment:
       do we also need `rocksdb.block-cache-pinned-usage`?




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] HyukjinKwon commented on pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on pull request #35480:
URL: https://github.com/apache/spark/pull/35480#issuecomment-1035709546


   cc @xuanyuanking too FYI


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #35480:
URL: https://github.com/apache/spark/pull/35480#issuecomment-1035852196


   Merged to master/3.2. Thank you, @Myasuka and all.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #35480:
URL: https://github.com/apache/spark/pull/35480#discussion_r804331106



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
##########
@@ -403,7 +404,7 @@ class RocksDB(
     RocksDBMetrics(
       numKeysOnLoadedVersion,
       numKeysOnWritingVersion,
-      readerMemUsage + memTableMemUsage,
+      readerMemUsage + memTableMemUsage + blockCacheUsage,

Review comment:
       Thank you for the detail, @Myasuka .




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Myasuka commented on a change in pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
Myasuka commented on a change in pull request #35480:
URL: https://github.com/apache/spark/pull/35480#discussion_r804334898



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
##########
@@ -403,7 +404,7 @@ class RocksDB(
     RocksDBMetrics(
       numKeysOnLoadedVersion,
       numKeysOnWritingVersion,
-      readerMemUsage + memTableMemUsage,
+      readerMemUsage + memTableMemUsage + blockCacheUsage,

Review comment:
       @viirya Thanks for your suggestions, I have already updated the PR description.




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun closed pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun closed pull request #35480:
URL: https://github.com/apache/spark/pull/35480


   


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] viirya commented on a change in pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
viirya commented on a change in pull request #35480:
URL: https://github.com/apache/spark/pull/35480#discussion_r804332598



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
##########
@@ -403,7 +404,7 @@ class RocksDB(
     RocksDBMetrics(
       numKeysOnLoadedVersion,
       numKeysOnWritingVersion,
-      readerMemUsage + memTableMemUsage,
+      readerMemUsage + memTableMemUsage + blockCacheUsage,

Review comment:
       Thank you. Maybe it is good to put a sentence in the PR description to mention the fact that "block-cache-pinned-usage" is included in "block-cache-usage", so we don't need to include it separately.




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] Myasuka commented on pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
Myasuka commented on pull request #35480:
URL: https://github.com/apache/spark/pull/35480#issuecomment-1035063327


   cc @zsxwing @viirya, please take a look.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on a change in pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on a change in pull request #35480:
URL: https://github.com/apache/spark/pull/35480#discussion_r804110939



##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDB.scala
##########
@@ -403,7 +404,7 @@ class RocksDB(
     RocksDBMetrics(
       numKeysOnLoadedVersion,
       numKeysOnWritingVersion,
-      readerMemUsage + memTableMemUsage,
+      readerMemUsage + memTableMemUsage + blockCacheUsage,

Review comment:
       +1 for @viirya 's comment.




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


[GitHub] [spark] dongjoon-hyun commented on pull request #35480: [SPARK-38178][SS] Correct the logic to measure the memory usage of RocksDB

Posted by GitBox <gi...@apache.org>.
dongjoon-hyun commented on pull request #35480:
URL: https://github.com/apache/spark/pull/35480#issuecomment-1035853386


   Welcome to the Apache Spark community, @Myasuka .
   You are added to the Apache Spark contributor group too and SPARK-38178 is assigned to you.


-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org