Skip to content
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

Very low number of RPC calls per second #430

Closed
alemariusnexus opened this issue Aug 18, 2020 · 1 comment
Closed

Very low number of RPC calls per second #430

alemariusnexus opened this issue Aug 18, 2020 · 1 comment

Comments

@alemariusnexus
Copy link
Contributor

I was testing how many RPC calls BlackBone can do per second, and was a bit disappointed when I found that on my machine, it could only do 65 calls per second. Now I'm sure there's a lot of overhead for executing remote code, but 65 sounds very low even when considering that. Now what I mean by "RPC call" is RemoteFunction::Call() in a dedicated worker thread, so basically RemoteExec::ExecInWorkerThread(). I looked at that method, and this line immediately jumped at me:

// Ensure APC function fully returns
Sleep( 1 );

Naive as I am, I just commented this line out, and the number of RPC calls per second rose to ~8800, a factor of more than 100 more. That's closer to what I hoped for. What's more: In my admittedly very basic and unscientific test (calling a single remote function repeatedly that adds two numbers and returns the result), everything was still working fine.

So what's the actual reason for this Sleep(1)? Is it really necessary? Is there no other easy way to wait for whatever this is waiting for that does not waste so much time? Or do you have another idea for getting more RPC calls per second out of BlackBone?

@alemariusnexus
Copy link
Contributor Author

I finally got around to checking on this again, and found out that the Sleep() can't simply be removed without further changes to the code. Doing that leads to rare crashes in KiUserApcDispatcher() because a new RPC call is started while the old one hasn't fully finished yet, overwriting data needed by the previous call.

The good news is that I hopefully solved it properly in this pull request, which avoids both the race condition and the arbitrary Sleep(), leading to pretty much the same factor 100 speed improvement without introducing instabilities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant