-
-
Notifications
You must be signed in to change notification settings - Fork 596
fix: Request execution time keeps increasing over time when using Parse.Object.extend
#1682
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
Conversation
I will reformat the title to use the proper commit message syntax. |
Thanks for opening this pull request!
|
Related: parse-community/parse-server#7036 |
Codecov ReportBase: 99.89% // Head: 99.89% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## alpha #1682 +/- ##
=======================================
Coverage 99.89% 99.89%
=======================================
Files 61 61
Lines 5977 5984 +7
Branches 1369 1372 +3
=======================================
+ Hits 5971 5978 +7
Misses 6 6
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
That's an amazing improvement! Hats off! Could this have an effect on the general performance of Parse Server if the JS SDK dependency of Parse Server is updated with this fix? I’m thinking if |
No, unless there are cloud code triggers that uses
I don't think extend is used at all internally |
I’ve updated my comment while you posted. If |
I'm pretty sure the method isn't used internally. I might just double check that this change doesn't break the tests on Parse Server before we merge |
Sure, thanks for checking |
Parse.Object.extend
Tests passing |
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.
Looks good! This will hopefully address these vague perf issue reports we're received over the years.
From the investigations this seems to go beyond a mere perf improvement and actually fix a bug. It seems that the execution time keeps increasing until the server slows down significantly. So I'll merge this as a bug fix.
Parse.Object.extend
Parse.Object.extend
Parse.Object.extend
Parse.Object.extend
# [4.0.0-alpha.7](4.0.0-alpha.6...4.0.0-alpha.7) (2023-01-30) ### Bug Fixes * Request execution time keeps increasing over time when using `Parse.Object.extend` ([#1682](#1682)) ([f555c43](f555c43))
🎉 This change has been released in version 4.0.0-alpha.7 |
## [4.0.1-beta.1](4.0.0...4.0.1-beta.1) (2023-01-31) ### Bug Fixes * Local datastore query with `containedIn` not working when field is an array ([#1666](#1666)) ([2391bff](2391bff)) * Request execution time keeps increasing over time when using `Parse.Object.extend` ([#1682](#1682)) ([f555c43](f555c43))
🎉 This change has been released in version 4.0.1-beta.1 |
🎉 This change has been released in version 4.0.1 |
Issue seems to be still existing even in Parse 4.1.0? I just ran into the same issue when calling Parse.Object.extend in a loop and it gets progressively slower in time. I initially thought my queries are poorly written but then I found this. |
@vscorpio can you share some pseudo-code, or write a failing test? |
@dblythy I have tested an whatever code creating rows gets slower in time. For example the following code: // Create a new ticket purchase event similar to the one produced by the SolanaIndexer class.
const TicketPurchaseEvent = Parse.Object.extend("EVENT_TicketPurchase");
const ticketPurchaseEvent = new TicketPurchaseEvent();
ticketPurchaseEvent.set("lottery_id", activeLottery?.get("lottery_id"));
ticketPurchaseEvent.set(
"ticket_number",
latestTicket?.get("ticket_number")
? latestTicket?.get("ticket_number") + 1
: 1
);
ticketPurchaseEvent.set("owner", owner);
// Save the object to the database.
await ticketPurchaseEvent.save(null, { useMasterKey: true }); Works perfect for the first 10 tries, but after the 10th iteration it gets progressively slower. CPU usage is never above 7%, Memory usage is negligible. |
I think it should be possible to write a test case for this, and test for example whether the execution time mean decreases more than x% over time. |
I have written this test and have not observed the issue @vscorpio - is there any cloud code / server rate limit or slowdown to consider? it('execution time should not increase', async () => {
const activeLottery = new Parse.Object('Lottery');
activeLottery.set('lottery_id', 'lotteryID')
const owner = new Parse.User();
owner.set({username: 'abc', password: '123'});
await Promise.all([
activeLottery.save(), owner.signUp()
])
let latestTicket = null;
for (let i = 0; i < 10000; i++) {
let start = new Date();
const TicketPurchaseEvent = Parse.Object.extend("EVENT_TicketPurchase");
const ticketPurchaseEvent = new TicketPurchaseEvent();
ticketPurchaseEvent.set("lottery_id", activeLottery?.get("lottery_id"));
ticketPurchaseEvent.set(
"ticket_number",
latestTicket?.get("ticket_number")
? latestTicket?.get("ticket_number") + 1
: 1
);
ticketPurchaseEvent.set("owner", owner);
// Save the object to the database.
await ticketPurchaseEvent.save(null, { useMasterKey: true });
latestTicket = ticketPurchaseEvent;
const end = new Date();
console.log('duration: ', end.getTime() - start.getTime());
}
}); |
Did you verify that this test would have failed pre-#1682? It's not part of the PR so if it hasn't been added to the tests yet and we can verify the test works it would be good to add it. There are also some caveats regarding code execution time measurement, so maybe rewrite the test using the Node built-in perf API and test the execution time variance between the mean of the first few and last few runs. That would also be a good template for other perf tests in the future. |
Testing with 50,000 requests and averaging execution times per 10,000 requests (using Parse JS SDK 4.0.0 (pre #1682): 0-9999 average duration: 7.8ms Parse JS SDK 4.1.0 (post #1682): 0-9999 average duration: 1.9ms |
Nice, I think you can just calculate the standard deviation of all runs (not of batches) for the test to pass or fail: pre-𝜎 = 51.02825 So the test could fail if 𝜎 >= 0.1 |
New Pull Request Checklist
Issue Description
new Parse.Object.extend("")
takes increasing execution time when ran in a loop, as it seems that the constructor somehow gets deep assigned each time, meaning that it is exponentially called.Closes: #1683
Approach
First commit shows the issue, with:
Timing out the CI, taking too long.
With these changes, this function only takes 38ms.
TODOs before merging