Closed WeiquanWa closed 1 year ago
ReadAsyncGoLimit sets the maximum number of OnMessage calls in parallel on a single connection. ReadAsyncCap sets the maximum number of messages to be stacked, overflowing will return an error and close the connection.
Thank you for your prompt reply.
ReadAsyncCap
should be always greater than ReadAsyncGoLimit
. right?ReadAsyncGoLimit sets the maximum number of OnMessage calls in parallel on a single connection.
Generally speaking, ReadAsyncCap does not need to be modified, it defaults to 256 and normal connections do not pile up so many messages. The default value of ReadAsyncGoLimit is 8, which can handle up to 8 requests in parallel, modify it if necessary.
gws read and write is thread-safe, reads serially, and processes business logic in parallel.
okay. if ReadAsyncEnabled
is false
, gws creates two read and write-goroutines of each new connection?
is it possible to read and write messages concurrently for single connection using gws?
is it possible to read and write messages concurrently using gws?
Unlike gorilla/websocket, gws' WriteMessage ensures thread safety
okay. if
ReadAsyncEnabled
isfalse
, gws creates two read and write-goroutines of each new connection?
One connection in gws will only create one goroutine for reading messages
to read and write concurrently, we will have to enable ReadAsyncEnabled
. please confirm
Not required, gws also provides the WriteAsync method, which starts a new goroutine to write the message.
If you want OnMessage to be processed in parallel, you need to turn it on, or implement your own concurrency control logic.
is it possible to read and write messages concurrently for single connection using gws?
This possibility exists.
okay cool
Looking at the source code, reader and writer are using a same buffer pool named myBufferPool
across all connections. Is it realistic if there are a lot of many concurrent connections and the packet size is large?
How big is it exactly? gws is not optimized for large packets (e.g. writing temporary files), and large packets will block the connection, I think this scenario should use HTTP, WebSocket messages with URLs in them.
I see, seems like the approach to manage memory in gws is a manner to reduce memory usage
There are two similar configs of
ReadAsyncGoLimit
andReadAsyncCap
. What's the differencies between them in terms of use cases?