On Fri, Mar 22, 2013 at 6:17 AM, 長島徹 <[email protected]> wrote:
> Hello everyone.
> (Sorry, my English is poor)
>
> I made a HTTP server.
> I am using "HTML5 Server-Sent Events" [http://dev.w3.org/html5/eventsource/]
> on the server to push notifications.
>
> Under the conditions, when a HTTP client was hung-up, then the HTTP server
> is hung-up!
>
> Flow is below:
>
> The client application hang-up.
> The server is sending push-notifications periodically.
> The receiving buffer of the socket for the client application becomes full.
> The sending buffer of the socket in the server becomes full.
> The writing queue of the socket in Nodejs is been increasing unlimited.
> Becomes to low memory at the server!
>
>
> I have considered that check the writing queue of the socket in Nodejs
> before writing push-notifications, and close the socket.
>
>     function writeUpdateEvent(res, data) {
>       if (res.socket._pendingWriteReqs > 1000) {
>         logger.warn('TCP Socket is TOO BUSY!!');
>         res.end();
>       }
>       else {
>         res.write('id: ' + data.id + '\n');
>         res.write('event: update\n');
>         res.write('data: ' + JSON.stringify(data) + '\n\n');
>       }
>     }
>
> But, the code has used two undocumented properties:
>
> http.ServerResponse.socket
> net.Socket._pendingWriteReqs
>
>
> What should I do better solutions?
> Or this way is right?
>
> Thanks.
>
> Toru Nagashima (長島 徹).

Check the return value of res.write().  If it's false (in the strict
equal sense, i.e. res.write(data) === false) you should stop writing
until you get a 'drain' event.

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to