Skip to content
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

Extend bufferedAmount property #970

Closed
alexions opened this issue Jan 17, 2017 · 1 comment
Closed

Extend bufferedAmount property #970

alexions opened this issue Jan 17, 2017 · 1 comment

Comments

@alexions
Copy link

alexions commented Jan 17, 2017

The bufferedAmount property is good for your application to control how much messages you can send (to avoid memory overhead), but it works only if you disable perMessageDeflate.

I propose to extend the property by calculating _sender.queue size as well.

Example:

get bufferedAmount () {
    var amount = 0;
    var senderQueueSize = 0;
    
    if (this._socket) amount = this._socket.bufferSize || 0;
    
    if (this._sender && this._sender.queue) {
      for (i = 0; i < this._sender.queue.length; i += 1) {
        senderQueueSize += this._sender.queue[i].data.length;
      }
    }
    return amount + senderQueueSize;
}

The best solution is to avoid cycle at all by adding queueSize variable to _sender and add/subtract length when adding a new element to queue.

get bufferedAmount () {
    var amount = 0;
    var senderQueueSize = 0;
    
    if (this._socket) amount = this._socket.bufferSize || 0;
    return amount + this._sender.queueSize;
}
@lpinca
Copy link
Member

lpinca commented Jan 17, 2017

It makes sense but it's slightly harder as, in some cases, the data to send is converted to a buffer only before writing to the socket. This can probably be fixed though by converting the data to a buffer before it is added to the queue.

Are you up for creating a PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants