Did you receive 1G of HTTP POST data, and this process consumes 1G of memory?

Source: Internet
Author: User
Tags node server
If memory is only 1 g, what happens next, like PHP, crashes?
In the case of node. JS, a single process would have a 1G memory limit. What's going to happen, collapse?

Reply content:

PHP seems to actually put the received request body into memory. So in order to avoid trouble, php.ini usually configure the maximum request body size limit, the default is usually 2MB, 4MB and so on, in short. Requests that exceed this limit will be dropped directly by 413.

And if you use node. js, this should depend on the person implementing the HTTP server's own settings. For example, I can write the received data to the hard disk, so as not to occupy the memory:
http.Createserver(function (req, Res) {  var FD = FS.OpenSync('/tmp/' + Math.Random(), ' w+ ');  req. on(' Data ', function (Chunk) {    FS.Writesync(FD, Chunk);  });  req. on(' End ', function () {    Callbackwithrequestbody(FD);    Res.End();  });});
Nodejs buffer memory seems to be another calculation, in addition, this super-large file upload is generally streaming, read how much write, memory consumption is not high. You can use streaming to get the flow of the request, slowly read and write slowly, and node server gets the request itself is to implement the readable stream of things
See Stream node. js v5.1.1 Manual & Documentation
Most web frameworks simply encapsulate the network stream that allows you to not touch the request body directly. No, all is the form of the stream, http/tcp the bottom is the TCP protocol, read and write have a certain buffer, the data or file through the flow of the form of writing to the local
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.