uNetworking / uWebSockets.js

μWebSockets for Node.js back-ends :metal:
Apache License 2.0
8.08k stars 574 forks source link

maxBackpressure not working #569

Closed vnStrawHat closed 3 years ago

vnStrawHat commented 3 years ago

Hi,

I have problem with option maxBackpressure that seen not work. For my understand, if ws.getBufferedAmount() > maxBackpressure => websocket have drained. I was set maxBackpressure = 100000 and print ws.getBufferedAmount() every 1s. The result of ws.getBufferedAmount() seen to be can not great than 66k. The maximum value is 65593, it lower than maxBackpressure but drain() still triggered

Bellow is sample code:

P/s: English is not my primary language. Sorry for that.

ghost commented 3 years ago

This is not how it works. You need to read the documentation for these options and events, and look at examples. There are plenty of comments regarding this. Drain event fires when backpressure drains, drainage can happen before reaching maxBackpressure.

vnStrawHat commented 3 years ago

Hi,

My case use pub/sub and I see in the document:

getBufferedAmount(): Returns the bytes buffered in backpressure

Publish(): Also keep in mind that backpressure will be automatically managed with pub/sub, meaning some outgoing messages may be dropped if backpressure is greater than specified maxBackpressure.

My concerns is:

e3dio commented 3 years ago

Drain event fires after it drains, not before: 100,000 - drain amount = 65,000