You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "sonatype-lift[bot] (via GitHub)" <gi...@apache.org> on 2023/04/19 04:58:14 UTC

[GitHub] [skywalking-python] sonatype-lift[bot] commented on a diff in pull request #300: Fix high CPU usage

sonatype-lift[bot] commented on code in PR #300:
URL: https://github.com/apache/skywalking-python/pull/300#discussion_r1170807243


##########
skywalking/agent/__init__.py:
##########
@@ -307,15 +309,24 @@ def stop(self) -> None:
     def __heartbeat(self) -> None:
         self.__protocol.heartbeat()
 
-    @report_with_backoff(reporter_name='segment', init_wait=0)
-    def __report_segment(self) -> None:
-        if not self.__segment_queue.empty():
+    # segment/log init_wait is set to 0.02 to prevent threads from hogging the cpu too much
+    # The value of 0.02(20 ms) is set to be consistent with the queue delay of the Java agent
+
+    @report_with_backoff(reporter_name='segment', init_wait=0.02)
+    def __report_segment(self) -> bool:
+        """Returns True if the queue is not empty"""
+        queue_not_empty_flag = not self.__segment_queue.empty()

Review Comment:
   <picture><img alt="3% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/3/display.svg"></picture>
   
   <b>*reportOptionalMemberAccess:</b>*  "empty" is not a known member of "None"
   
   ---
   
   <details><summary>ℹī¸ Expand to see all <b>@sonatype-lift</b> commands</summary>
   
   You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   <b>Help us improve LIFT! (<i>Sonatype LiftBot external survey</i>)</b>
   
   Was this a good recommendation for you? <sub><small>Answering this survey will not impact your Lift settings.</small></sub>
   
   [ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=497536905&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=497536905&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=497536905&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=497536905&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=497536905&lift_comment_rating=5) ]



##########
skywalking/agent/__init__.py:
##########
@@ -307,15 +309,24 @@ def stop(self) -> None:
     def __heartbeat(self) -> None:
         self.__protocol.heartbeat()
 
-    @report_with_backoff(reporter_name='segment', init_wait=0)
-    def __report_segment(self) -> None:
-        if not self.__segment_queue.empty():
+    # segment/log init_wait is set to 0.02 to prevent threads from hogging the cpu too much
+    # The value of 0.02(20 ms) is set to be consistent with the queue delay of the Java agent
+
+    @report_with_backoff(reporter_name='segment', init_wait=0.02)
+    def __report_segment(self) -> bool:
+        """Returns True if the queue is not empty"""
+        queue_not_empty_flag = not self.__segment_queue.empty()
+        if queue_not_empty_flag:
             self.__protocol.report_segment(self.__segment_queue)
+        return queue_not_empty_flag
 
-    @report_with_backoff(reporter_name='log', init_wait=0)
-    def __report_log(self) -> None:
-        if not self.__log_queue.empty():
+    @report_with_backoff(reporter_name='log', init_wait=0.02)
+    def __report_log(self) -> bool:
+        """Returns True if the queue is not empty"""
+        queue_not_empty_flag = not self.__log_queue.empty()

Review Comment:
   <picture><img alt="3% of developers fix this issue" src="https://lift.sonatype.com/api/commentimage/fixrate/3/display.svg"></picture>
   
   <b>*reportOptionalMemberAccess:</b>*  "empty" is not a known member of "None"
   
   ---
   
   <details><summary>ℹī¸ Expand to see all <b>@sonatype-lift</b> commands</summary>
   
   You can reply with the following commands. For example, reply with ***@sonatype-lift ignoreall*** to leave out all findings.
   | **Command** | **Usage** |
   | ------------- | ------------- |
   | `@sonatype-lift ignore` | Leave out the above finding from this PR |
   | `@sonatype-lift ignoreall` | Leave out all the existing findings from this PR |
   | `@sonatype-lift exclude <file\|issue\|path\|tool>` | Exclude specified `file\|issue\|path\|tool` from Lift findings by updating your config.toml file |
   
   **Note:** When talking to LiftBot, you need to **refresh** the page to see its response.
   <sub>[Click here](https://github.com/apps/sonatype-lift/installations/new) to add LiftBot to another repo.</sub></details>
   
   
   
   ---
   
   <b>Help us improve LIFT! (<i>Sonatype LiftBot external survey</i>)</b>
   
   Was this a good recommendation for you? <sub><small>Answering this survey will not impact your Lift settings.</small></sub>
   
   [ [🙁 Not relevant](https://www.sonatype.com/lift-comment-rating?comment=497536911&lift_comment_rating=1) ] - [ [😕 Won't fix](https://www.sonatype.com/lift-comment-rating?comment=497536911&lift_comment_rating=2) ] - [ [😑 Not critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=497536911&lift_comment_rating=3) ] - [ [🙂 Critical, will fix](https://www.sonatype.com/lift-comment-rating?comment=497536911&lift_comment_rating=4) ] - [ [😊 Critical, fixing now](https://www.sonatype.com/lift-comment-rating?comment=497536911&lift_comment_rating=5) ]



-- 
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: notifications-unsubscribe@skywalking.apache.org

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