public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: Akshay Joshi <[email protected]>
Cc: pgadmin-hackers <[email protected]>
Subject: Re: [pgAdmin][RM5794] Excessive CPU usage while browser is idle
Date: Wed, 9 Sep 2020 11:39:15 +0530
Message-ID: <CAM9w-_nAgMea=F9Yk_psM0e=jDb9Q+Cqt3qUzgomNvnRTSOQzw@mail.gmail.com> (raw)
In-Reply-To: <CANxoLDcGNQXXFVRbp2oi5TeTo1uPoW0RsHrU2MzUrk+kQVQxWA@mail.gmail.com>
References: <CAM9w-_=2zjuSTFQrkn=4DUBK7T5zk-SEN4RYn2KPMfHMSkj7UA@mail.gmail.com>
	<CANxoLDcGNQXXFVRbp2oi5TeTo1uPoW0RsHrU2MzUrk+kQVQxWA@mail.gmail.com>

Hi,

In the previous patch, I had changed the react state directly, which is not
recommended and can cause unpredictable behavior.
Attached patch changes the previous commit to avoid changing state directly.

Please review.

On Mon, Sep 7, 2020 at 6:48 PM Akshay Joshi <[email protected]>
wrote:

> Thanks, patch applied.
>
> On Mon, Sep 7, 2020 at 3:59 PM Aditya Toshniwal <
> [email protected]> wrote:
>
>> 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"
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Sr. Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>


-- 
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.part2.patch (1.1K, 3-RM5794.part2.patch)
  download | inline diff:
diff --git a/web/pgadmin/dashboard/static/js/Graphs.jsx b/web/pgadmin/dashboard/static/js/Graphs.jsx
index e8862a109..ad2b3cf92 100644
--- a/web/pgadmin/dashboard/static/js/Graphs.jsx
+++ b/web/pgadmin/dashboard/static/js/Graphs.jsx
@@ -80,15 +80,20 @@ export function statsReducer(state, action) {
     action.counterData = action.incoming;
   }
 
+  let newState = {};
   Object.keys(action.incoming).forEach(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();
+    if(state[label]) {
+      newState[label] = [
+        action.counter ?  action.incoming[label] - action.counterData[label] : action.incoming[label],
+        ...state[label].slice(0, X_AXIS_LENGTH-1),
+      ];
+    } else {
+      newState[label] = [
+        action.counter ?  action.incoming[label] - action.counterData[label] : action.incoming[label],
+      ];
     }
-    state[label].unshift(newEle);
   });
-  return state;
+  return newState;
 }
 
 const chartsDefault = {


view thread (3+ messages)

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], [email protected]
  Subject: Re: [pgAdmin][RM5794] Excessive CPU usage while browser is idle
  In-Reply-To: <CAM9w-_nAgMea=F9Yk_psM0e=jDb9Q+Cqt3qUzgomNvnRTSOQzw@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