-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve page load performance of large amount urls #5025
improve page load performance of large amount urls #5025
Conversation
1) fix loop to async 2) query n+1 problem
moved changes while testing
I debug & fix performance issues for below monitor url count: 415 after changes: I just updated the target record with the front end instead of all records. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late review, I am currently quite stressed work-wise..
While the ~16x(!) performance improvement in this PR is great, I don't quite like how you implemented some parts.
(most parts are fine)
preloadData
is quite clunky
=> please move this into a single object per toJSON
that we pass to the function instead of the current way of passing a lookup-object into the function.
The current way is quite likely error prown and without tests whatsoever way in this part extremely risky.
Only passing an object also has the advantage of allowing better type-checking via adding what is passed in to the doc-comment.
I have also left some comments below
server/model/monitor.js
Outdated
); | ||
|
||
// Organize preloaded data for efficient access | ||
return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the .reduce
calls with object-changes here are really hard to parse for me and thus likely other devs.
If there were a bug in here, I would not be able to tell.
Please move this into regular for-loops.
While moving this, please also check if Map
is not more appropriate.
I found this blog post with some claims that this might increase performance (if that code happends to be a factor we are spending a part of the remaining 700ms
..)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CommanderStorm
understand let me double check with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CommanderStorm
I simplified logic. can you review one more time.
server/uptime-kuma-server.js
Outdated
let list = await this.getMonitorJSONList(socket.userID); | ||
this.io.to(socket.userID).emit("monitorList", list); | ||
return list; | ||
async sendMonitorList(socket, op = OPERATIONS.LIST, monitorID = null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty strange
the whole part why you added op
here and above seems to be to create a fast-path for OPERATIONS.DELETE
, right?
Instead of doing this, please just remove the calls for OPERATIONS.DELETE
if we really don't use the list
there..
Cleans up the code a lot..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CommanderStorm
its used as common method. based on this parameter we will identified operation & update same to frontend list. you can refer socket.js changes
while page load it will use OPERATIONS.LIST as default.
while insert or update. we will add only 1 URL object to list.
while delete no need to send list because we have to delete from fronted list. from backend already deleted.
Thank you for your effert to review my pr. i am really appreciate your hard work for community.
|
yes, you are correct. i didn't think about it. we will do in next pr. but we should restrict max span. because for detail information already provided graph. |
move inner promise to outer promise
made code clean make it faster
move path to preload function
@CommanderStorm i did testing with 800 records. when I remove below line. all monitoring is working fine but current case most of monitor is stopped. monitoring data is not updating so monitor is not starting. |
Sorry, above comment does not quite parse for me. As far as I understand that line, this just means that the monitors are started one after another with random intervals in between. The way this is executed, starting monitors should happen after the server started listening, but must not have completely/partially completed before starting the As far as I understand async js (feel free to correct), that sounds partially reasonable. |
revert to original insted of map
@CommanderStorm |
@CommanderStorm |
Sorry, got back from vacation on monday and am still picking up the pieces work wise and had not time for such a large PR. |
@CommanderStorm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have left a few nits to apply, but mostly LGTM 🎉
Note
This PR is part of the v2.0
merge window => see #4500 for the bugs that need to be addressed before we can ship this release ^^
All changes in this PR are small and uncontroversial ⇒ merging with junior maintainer approval
for (let monitorID in monitorList) { | ||
await sendHeartbeatList(socket, monitorID); | ||
monitorPromises.push(sendHeartbeatList(socket, monitorID)); | ||
monitorPromises.push(Monitor.sendStats(io, monitorID, user.id)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vishalsabhaya Just checking this pr. Is this code correct? Because the function returns nothing.
@CommanderStorm @louislam
Tick the checkbox if you understand [x]:
Description
Resolves #5129
testing results:
monitor url count: 415
current:
cpu: 1 memory 2 gb: 1 min 44 sec
after changes
database: aws rds marinadb db.t3.micro(memory: 1gb, cpu: 2vcpu)
with docker run on mac:
cpu: 0.5 memory 1 gb: 21 sec
cpu: 1 memory 2 gb: 11 sec
cpu: 1.5 memory 3 gb: 10 sec
cpu: 2 memory 4 gb: 10 sec
with ESC Farget(Linux/ARM64):
cpu: 0.5 memory 1 gb: 31 sec
cpu: 1 memory 2 gb: 6 sec
cpu: 2 memory 4 gb: 5 sec
Fixes #3494
Type of change
Checklist
Screenshots (if any)