-
Notifications
You must be signed in to change notification settings - Fork 6
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
Faster upsert #37
Faster upsert #37
Conversation
✅ Deploy Preview for metaforecast ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Ugh, npm decided to remove some stuff from my package-lock.json for some reason, I thought it was fine but it isn't, and netlify build fails now. Upd: oh, it installed @next/swc-darwin-arm64 instead of linux version. |
Rebased on top of fresh #34 changes. One more benchmark: on my local db (incomplete, includes only some platforms):
On prod:
|
Also: this speed-up might be almost entirely due to ping distance from Heroku to DO. I checked the ping distance with tcp-ping from Heroku to DO and it's not good:
So, for 5000 rows inserted one by one it would take... actually, 450 seconds instead 330, not sure what that's about :) This might be the good reason to move from Heroku to DO, or at least to look into whether there's a Heroku-DO datacenter pair with lower ping distance. Also, this might eventually cause us to move API back from Netlify closer to the DB (but still keep it implemented with Next.js); if our APIs will become more complicated and require multiple DB queries then ping distance will heavily affect its performance. Single-query requests shouldn't be affected by this, though: Netlify probably runs its functions on edge close to the user, and user->db ping distance is unavoidable (at least without much more complicated setups with db replicas on each continent, which we surely don't want to deal with now). |
Yeah, I previouusly prefered to have my DO instance in Europe (data protection laws are better). But I changed it to the US in the new team database. |
PR for #30.
DELETE FROM
table instead of dropping & recreatingpgBulkInsert
code which replacedpgInsert
)measureTime
higher order function for common "Took X seconds, or Y minutes." logging patternDELETE FROM
by itself haven't brought any performance improvements, in fact, it made the code significantly slower (but it's still the right thing to do, transaction safety-wise, otherwise frontpage update could coincide with merge job and then the frontpage would be empty).Bulk inserts are fast. In my local tests time for polymarket upserts went down from 35 seconds to 5.
PS: This PR is stacked on top of #34.