-
Notifications
You must be signed in to change notification settings - Fork 155
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
Does this library take an advantage of zero-copy upgrade in Websocket? #309
Comments
Thank you for your attention!
The I don't so agree with the definitions defined by
For benchmark, I suggest users run the test themselves.
If use std's http.Server, and nbio's websocket Upgrade, with the std TCPConn/tls.Conn, it's just like gorilla, nbio also use 1 goroutine to handle reading, and if you set upgrader.BlockingModAsyncWrite = true, will use dynamic goroutine to handle writing. nbhttp.Engine has different IOMod, for more details please refer to README, or here: |
In the latest version, nbhttp/websocket supports more Upgrade style, for example:
There are many other different styles that I don't wanna list here, but I can give some example code if you tell the scenario you want. |
If using nbio poller to manage connections, and there are not a huge num of connections, nbio's qps/tps may be lower than std-based frameworks. But if there're lots of connections, it saves lots of goroutine and won't STW as easily as std-based frameworks, and may performs a better qps/tps than them. Of course, users can use |
@lesismal thank you for your kind reply.
|
We're still back and forth on determining which library will be used for a high performance ws. |
It should be fine if using gobwas/ws with std http.Server together. For more details: |
If your service is not high online, I would like to suggest to keep using gorilla or melody, or there's a new framework gws, If your service has huge amount of connections and want reduce your hardware usage, or want to keep balance between performance and hardware usage, nbio would be better. |
I'm a bit confused between IOModNonBlocking vs IOModBlocking vs IOModMixed. From my understanding,
Please confirm if it's right. |
Yes, that's right!
This is also right!
That's not exactly right. For more details: |
I've measured the number of goroutines running under the IOModBlocking + BlockingModAsyncWrite=true. The number of connections is incremented by 2 for each new connection. I think it intends to create two goroutines for async reading and writing from a new connection? |
For 1 connection, at most 1 goroutine for async write. |
Version: 1.3.15
With the above changes, |
After you open this issue, I create a benchmark repo to compare different frameworks, would like to invite you to try it here: |
Great. I will upgrade the version and try benchmark. I have another questions.
|
I already update nbio-examples's nbio version to v1.3.16, please just pull nbio-examples. |
Please update to v1.3.16, src changed a lot.
In the latest version, you can set it like this:
Because |
func broadcast() {
for _, conn := range allConns {
// std's TCPConn/tls.Conn.Write may block when tcp send queue in kernal is full
// then, other conns in this for-loop would waiting too
// it's kind of like Head-of-line blocking, HOL
conn.WriteMessage(...)
}
} |
@lesismal thank you for your details again. Maybe my last question is how to implement JWT authorization with |
It should be the same as your implementation using std http.Server. |
okay. is there any option to set ping/pong interval? The current websockget upgrader enables ping/pong handler by default? |
I think the best way to check zombie connections is:
For the server-side, nbio provide a easy way: upgrader.KeepaliveTime = YourKeepaliveInterval Then nbio will update ReadDeadline automatically: So, you just need to set
Yes, there are some handlers set by default: |
This feature is very useful. By the way, based on my testing, the function |
Please provide full example code, both server and client. |
ah, I've figured out why the |
Hi,
I've reached this library across gorilla/websocket and gobwas/ws libraries because I thought this would smoothly support 1M websocket connections. Looking at the sample codes, it's appeared this library uses http upgrade mode not tcp upgrade(inspired by zero-copy upgrade). Is there any benchmark result between gorilla, gobwas and this in terms of resource utilization, speed, scaling and etc?
The text was updated successfully, but these errors were encountered: