public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin][RM5794] Excessive CPU usage while browser is idle
Date: Mon, 7 Sep 2020 15:59:02 +0530
Message-ID: <CAM9w-_=2zjuSTFQrkn=4DUBK7T5zk-SEN4RYn2KPMfHMSkj7UA@mail.gmail.com> (raw)

Hi Hackers,

Attached is the patch to stop the indefinite growth of graph dataset. This
has caused excessive CPU usage and the patch will reduce it.

Please review.

-- 
Thanks,
Aditya Toshniwal
pgAdmin hacker | Sr. Software Engineer | *edbpostgres.com*
<http://edbpostgres.com;
"Don't Complain about Heat, Plant a TREE"


Attachments:

  [application/octet-stream] RM5794.patch (1.6K, 3-RM5794.patch)
  download | inline diff:
diff --git a/web/pgadmin/dashboard/static/js/Graphs.jsx b/web/pgadmin/dashboard/static/js/Graphs.jsx
index ac1c1605f..43333fe71 100644
--- a/web/pgadmin/dashboard/static/js/Graphs.jsx
+++ b/web/pgadmin/dashboard/static/js/Graphs.jsx
@@ -82,21 +82,14 @@ export function statsReducer(state, action) {
   }
 
   Object.keys(action.incoming).forEach(label => {
-    if(state[label]) {
-      if(state[label].length >= X_AXIS_LENGTH) {
-        state[label].unshift();
-      }
-      newState[label] = [
-        action.counter ?  action.incoming[label] - action.counterData[label] : action.incoming[label],
-        ...state[label],
-      ];
-    } else {
-      newState[label] = [
-        action.counter ?  action.incoming[label] - action.counterData[label] : action.incoming[label],
-      ];
+    let newEle = action.counter ?  action.incoming[label] - action.counterData[label] : action.incoming[label];
+    state[label] = state[label] || [];
+    if(state[label].length >= X_AXIS_LENGTH) {
+      state[label].pop();
     }
+    state[label].unshift(newEle);
   });
-  return newState;
+  return state;
 }
 
 const chartsDefault = {
@@ -263,6 +256,7 @@ export function GraphsWrapper(props) {
   const toStatsLegendRef = useRef();
   const bioStatsLegendRef = useRef();
   const options = useMemo(()=>({
+    normalized: true,
     legendCallback: legendCallback,
     animation: {
       duration: 0,
@@ -385,4 +379,4 @@ GraphsWrapper.propTypes = {
   showTooltip: PropTypes.bool.isRequired,
   showDataPoints: PropTypes.bool.isRequired,
   isDatabase: PropTypes.bool.isRequired,
-};
\ No newline at end of file
+};


view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin][RM5794] Excessive CPU usage while browser is idle
  In-Reply-To: <CAM9w-_=2zjuSTFQrkn=4DUBK7T5zk-SEN4RYn2KPMfHMSkj7UA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox