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

How to make sure we run the spacemonkey with non blocking BIO #89

Open
varunitgithub opened this issue May 1, 2018 · 2 comments
Open

Comments

@varunitgithub
Copy link

cgo marks all C calls as syscall causing scheduler to allocate a new thread everytime. This leads to scaling issues of applications, Is it possible to make the BIO as non blocking in which case most of the thread lock time will be highly optimized.

@zeebo
Copy link
Member

zeebo commented May 1, 2018

It doesn't allocate a new thread every time: it manages a pool and will only allocate a thread if the pool is empty.

I believe it is already the case that all of the calls into C are not blocking. Can you provide an example of a blocking C call?

@pvoicu
Copy link

pvoicu commented May 3, 2018

The potential blocking is caused by the contention on the map holding callback pointer parameters. https://github.com/spacemonkeygo/openssl/blob/master/bio.go#L54 . I believe spacemonkeygo uses the mapping defined in mapping.go to help in case the garbage collector moves the GO pointer, so the conversion from C int to the GO pointer is still valid.
This map protected by one global mutex is source of contention, and it matters for high load. I propose replacing with sync.Map or maybe some type of lock-free hash map. This is a simple change.
A more complex change would be to rewrite the BIO callbacks in C (from GO - go_read_bio_read, go_write_bio_ctrl, go_write_bio_write). Benefits are:

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

3 participants