Node.js vs. PHP CLI server Performance test for HTTP server

Source: Internet
Author: User
Tags fpm php cli

Environment:

64-bit ubuntu14.04,i5-3230m
PHP5.4.31 with Zendopcache
Node.js 0.10.35

Node.js Test

var http = require (' http ');
Http.createserver (function (req, res) {
Res.writehead ({' Content-type ': ' Text/html;charset=utf-8 '});
Res.write (' <! DOCTYPE html>Res.end ();
}). Listen (8082, ' 127.0.0.1 ');

To run the program:

Node T.js

To view the system CPU idle rate:

SAR 1

Stress test, concurrent 100, complete 100,000 requests:

ab-c100-n100000 Http://127.0.0.1:8082/t.js

Memory from 11MB to 61MB, the system CPU idle rate 65%, RPS reached 6049.


PHP CLI Server Test

<?php header (' Content-type:text/html;charset=utf-8 ');?>
<! DOCTYPE html>

To run the program:

Php-s 127.0.0.1:8081-t./

To view the system CPU idle rate:

SAR 1

Stress test, concurrent 100, complete 100,000 requests:

ab-c100-n100000 http://127.0.0.1:8081/t.php
Memory from 19.6MB to 20.0MB, the system CPU idle rate 57%, RPS reached 11405.

When the Opcache is not turned on, the memory rises from 8.3MB to 9.0MB, the system CPU idle rate 57%,rps reaches 8851.


PHP swoole Test

<?php
$http = new Swoole_http_server ("0.0.0.0", 9501);
$http->set ([
' Worker_num ' => 5//Open 5 working processes
]);
$http->on (' request ', function (swoole_http_request $request, Swoole_http_response $response) {
$response->header (' Content-type ', ' text/html;charset=utf-8 ');
$response->end (' <! DOCTYPE html>});
$http->start ();

To run the program:

PHP swoole.php

To view the system CPU idle rate:

SAR 1

Stress test, concurrent 100, complete 200,000 requests:

ab-c100-n200000 http://127.0.0.1:9501/swoole.php

After the test memory occupancy reaches 117MB, System CPU idle rate 39%, RPS reach 19216.

Conclusion: Both Node.js and PHP CLI server are single process HTTP requests, but RPS PHP is almost node.js twice times the memory footprint of PHP is only 1/3 of Node.js. Node.js It is commendable that the system CPU idle rate is 8% higher than PHP. PHP swoole Application of multiple processes and multithreading, RPS near 20K, the full use of multi-core, so the CPU idle rate is the lowest of the three. In addition, although the HTTP protocol is not supported by PHP-FPM, the performance of processing PHP requests is no worse than that of the PHP CLI server, and PHP-FPM can enable multiple processes to take full advantage of multi-core.

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.