-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
🤔 Use Context in websocket Conn? #205
Comments
This is something that was on my mind when implementing websockets into fiber, we might move the Conn inside the Ctx ( |
@Fenny Thanks a lot! |
Locals will be added to the |
Just landed here, so Fiber has websockets support already? What ws lib is used? Most performed Gobwas/ws? |
@coderbuzz hi! Fiber use Fasthttp Websocket lib via middleware https:/gofiber/websocket |
@koddr hi, Comes from NodeJS, in Node there is uWebSockets library which very perform. Sadly the author won't make the library available in Go. Based on benchmark above; Gobwas/ws seems most performed. Curious any benchmark result for Fasthttp Websocket vs Gobwas/ws? |
@coderbuzz, In my opinion uWebSockets is currently only useful for route levels. When we talk about proper concurrency inside the request handler, the benchmarks don't lie. Lets for example calculate 10 MD5 hashes (which is super fast) to simulate some processing that might happen:
uWebsocketjs // Thread Stats Avg Stdev Max +/- Stdev
// Latency 9.36ms 3.30ms 48.12ms 67.27%
// Req/Sec 43.02k 2.47k 47.12k 74.00%
const crypto = require('crypto');
const uws = require('uWebSockets.js');
var app = uws.App()
app.get('/*', (res, req) => {
for (let i = 0; i < 10; i++) {
const h = crypto.createHash('md5').update('foobar').digest('hex');
if (h !== '3858f62230ac3c915f300c664312c63f') {
throw h;
}
}
res.end('Hello World!');
})
app.listen(8080, () => {}); Fiber // Thread Stats Avg Stdev Max +/- Stdev
// Latency 2.82ms 363.98us 6.02ms 84.98%
// Req/Sec 140.72k 5.03k 148.43k 75.00%
package main
import (
"crypto/md5"
"encoding/hex"
"github.com/gofiber/fiber"
)
func main() {
app := fiber.New()
app.Get("/", func(c *fiber.Ctx) {
for i := 0; i < 10; i++ {
b := md5.Sum([]byte("foobar"))
h := hex.EncodeToString(b[:])
if h != "3858f62230ac3c915f300c664312c63f" {
panic(h)
}
}
c.SendString("Hello, World!")
})
app.Listen(8080)
} |
@hyingreborn |
So, what's the solution now ? |
Seems just use conn.Locals(). |
Question description
Code snippet (optional)
main.go
wsHandler
The text was updated successfully, but these errors were encountered: