Comments (8)
So we don't use sync.Pool
directly. We use json.Encoder
which uses sync.Pool
under the hood.
I haven't looked at that issue in detail yet but I would say it's on the Go team to fix json.Encoder
if there are performance concerns with the use of sync.Pool internally.
See also #409
from websocket.
You use it here: https://github.com/nhooyr/websocket/blob/master/internal/bpool/bpool.go
Called from: https://github.com/nhooyr/websocket/blob/master/wsjson/wsjson.go#L29-L30
from websocket.
Ah right sorry. I don't know if I agree that the concern outlined in that issue applies here. Most websocket protocols have similar sized messages and certainly not near 256 MiB in one frame and 1 KiB in another. For the general use case I think wsjson
reusing memory is the correct decision.
I would say though that documentation regarding this tradeoff is warranted. And that it's easy to write your own helpers with encoding/json if you don't want to reuse memory or if you want to reuse memory in more clever ways like limiting the size of buffers returned to the pool.
from websocket.
Maybe we adopt the same fix as the fmt package and limit the buffer size to 64 KiB? https://go-review.googlesource.com/c/go/+/136116
from websocket.
The issue is that if only 1% of messages are 1 MB, then quickly all buffers become 1 MB forever. Even if 99% of messages are 1 KB.
from websocket.
Right but most websocket protocols in my experience don't have that kind of variability between their messages. For example, the frame read limit in this library is just 32768. While it's adjustable, there haven't been any complaints that this isn't a reasonable default.
More potential solutions/ideas at:
- golang/go#27735
- https://go-review.googlesource.com/c/go/+/455236
- https://go-review.googlesource.com/c/go/+/471200
from websocket.
Also your PR here: rs/zerolog#602
from websocket.
Good summary here from you: rs/zerolog#602 (comment)
from websocket.
Related Issues (20)
- Examples: CloseNow does not exist HOT 1
- discussion: strange API for the common use case HOT 2
- wspb: Unexpected removal of publicly used module broke everything! HOT 3
- wasm not working for unknown reason HOT 6
- Configurable buffer sizes HOT 1
- Best practice for Wasm NetConn HOT 3
- Please return non-generic errors from dial HOT 1
- Document how to have read timeout be larger than idle timeout HOT 3
- all goroutines are dead asleep - deadlock! wasm docs HOT 8
- Deadlocks due to CloseRead HOT 6
- Can't activate CORS for examples /chat/ HOT 2
- Reader() can only read one message, but Read() can read all messages HOT 5
- Error: panic: unaligned 64-bit atomic operation on arm32-bit while establishing websocket connection HOT 2
- Invalid readme example HOT 3
- Goroutine spike when closing connections in v1.8.10 (regression) HOT 3
- Transmit only single frame in Write when compression enabled too HOT 6
- Data race on `Conn.closeErr` HOT 3
- websocket.Conn.CloseNow() panics in WaitGroup.Wait HOT 2
- failed to get reader: use of closed network connection HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from websocket.