-
Notifications
You must be signed in to change notification settings - Fork 697
Run async libgit2 calls on custom threadpool #1019
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
1890f6c to
46938f2
Compare
|
Innnnnnnnnteresting. |
46938f2 to
9b61269
Compare
|
@joshaber yep, the time has come to finalize this :-) With the recent libgit2 upgrade, libgit2 no longer locks the index internally. That makes it more important to turn on nodegit's thread safety, but the locking increases the burden on node's threadpool and can lead to long delays and deadlocks like we've discussed. Hopefully, this PR will avoid those issues and make thread-safe nodegit run better. |
9b61269 to
09b9f81
Compare
|
wow, that's very interesting. |
09b9f81 to
f9e0459
Compare
|
Why this is needed: So with running async libgit2 threads with thread-safety we're enqueuing them with the internal libuv thread pool which in node is hardcoded to 4 (IIRC). This hits us hard because we also share a thread with node so that leaves us with 3 threads to pull from. That sucks because say you're running a libgit2 function that has multiple callbacks. So we have 1 thread for node, 1 thread for the original call for libgit2, a 1 thread for each callback. Let's assume that those callbacks are also going to go run libgit2 code. 💥 thread lock. So as a first step this is 👍 but we talked offline about this and think that we need a better system to use a vector and grow the thread pool if needed and then shrink down when not. |
d10dcee to
ed61ea0
Compare
|
@nodegit/owners OK folks, I made most of the updates to the code that I wanted to - if anyone has a little time to spare I would love to get feedback. The main parts are:
As mentioned eariler, the reason for this PR is to get our async calls off libuv's threadpool, and avoid slowdowns and deadlocks resulting from needing more threads than available. This issue was anticipated by @saper in #827 (comment), we have seen it in GitKraken when we tried turning on NodeGit's thread-safety locking, and IIRC @joshaber reported seeing it in Atom as well. The PR currently uses 10 dedicated threads for async libgit2 calls - it is not a well thought-out number but it's >4 and dedicated :-) I've considered exposing some statistics to javascript, for example the number of async handles opened by (the CI is failing, but it looks like it's problems with AppVeyor and Travis - it was green yesterday before the final code cleanup) |
|
CI died due to network issues. I'm re-running the tests. |
|
Which sucks. Every day I wake up and say to myself, "today I'll make the unit tests work offline..." |
|
Me too @tbranyen. Me too :( |
|
Testing this in GK right now. |
|
We did run into some problems during testing in GitKraken. It worked well for the most part, but on windows we were seeing frequent app restarts. Commenting out calls to @joshaber - @johnhaley81 suggested I ping you about this - any ideas? |
|
Unfortunately I don't know much about Electron's internals. 😞 You could try opening an issue on the repo. |
ed61ea0 to
41e39b4
Compare
41e39b4 to
21f65d2
Compare
|
The problem ended up being on my end - I took |
|
We are running this build in production over in GitKraken land and things look 💯 so barring any feedback I'm going to go ahead an merge this in. Awesome job @srajko 👍 |
|
I'm not really qualified to review this PR, so I'll just 🎉 |
|
It's alright @tbranyen, we love you anyways. @joshaber @saper @implausible? |
|
Looks reasonable to me 👍 Thanks @srajko! |
No description provided.