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

Two questions about performance #133

Closed
rock59 opened this issue Sep 6, 2020 · 5 comments
Closed

Two questions about performance #133

rock59 opened this issue Sep 6, 2020 · 5 comments
Assignees
Labels
help wanted Extra attention is needed pending development Requested PR owner to improve code and waiting for the result question Further information is requested waiting for response waiting for the response from commenter

Comments

@rock59
Copy link

rock59 commented Sep 6, 2020

1- I need to use a nonblocking C library in io loops. The library uses thread local storage so I have to use LockOSThread in each io loop. Is it safe and does it affect gent performance (Excluding cgo overhead) ?

2- Gnet's thread pool system uses channels to pass blocking tasks to worker goroutines. I guess using channels , mutexes and anything else that cause go scheduler to switch goroutines may affect performance of io loops. Am I correct ?

@rock59 rock59 added help wanted Extra attention is needed question Further information is requested labels Sep 6, 2020
@xscode-auto-reply
Copy link

Thanks for opening a new issue. The team has been notified and will review it as soon as possible.
For urgent issues and priority support, visit https://xscode.com/panjf2000/gnet

@panjf2000
Copy link
Owner

1- I need to use a nonblocking C library in io loops. The library uses thread local storage so I have to use LockOSThread in each io loop. Is it safe and does it affect gent performance (Excluding cgo overhead) ?

Where do you call LockOSThread to lock each IO loop goroutine to a specified thread?

2- Gnet's thread pool system uses channels to pass blocking tasks to worker goroutines. I guess using channels , mutexes and anything else that cause go scheduler to switch goroutines may affect performance of io loops. Am I correct ?

goroutine pool ants uses mutex+LIFO queue for delivering tasks instead of channel. If you are worried about blocking IO loop goroutine by mutex, you can leverage the nonblocking mechanism of ants to avoid blocking IO loop goroutines, https://github.com/panjf2000/ants/blob/master/options.go#L33

@panjf2000 panjf2000 added the waiting for response waiting for the response from commenter label Sep 11, 2020
@rock59
Copy link
Author

rock59 commented Sep 11, 2020

@panjf2000 Thanks for your response.

Where do you call LockOSThread to lock each IO loop goroutine to a specified thread?

I need to call LockOSThread at the start of IO loop goroutine (the server startup) and call UnLockOSThread at the server shutdown.

@panjf2000
Copy link
Owner

panjf2000 commented Sep 11, 2020

@panjf2000 Thanks for your response.

Where do you call LockOSThread to lock each IO loop goroutine to a specified thread?

I need to call LockOSThread at the start of IO loop goroutine (the server startup) and call UnLockOSThread at the server shutdown.

I'm afraid that it won't work as you expected, OnInitComplete happens before I/O loops start running, so you're not going to get the results you want with calling runtime. LockOSThread () in OnInitComplete.

As currently structured, locking the I/O loop to a thread can't be done at the user level, it can only be done by modifying the source code and provide a functional option for users to determine whether to lock each I/O loop to a specified thread.

@panjf2000
Copy link
Owner

I'll have this feature up and running by the end of the week, stay tuned!

@panjf2000 panjf2000 added the pending development Requested PR owner to improve code and waiting for the result label Sep 13, 2020
panjf2000 added a commit that referenced this issue Sep 13, 2020
0-haha pushed a commit to 0-haha/gnet that referenced this issue Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed pending development Requested PR owner to improve code and waiting for the result question Further information is requested waiting for response waiting for the response from commenter
Projects
None yet
Development

No branches or pull requests

2 participants