2016-06-22 44 views
2

数年前、私はnode.jsとapache 2をテストしました。結果は印象的でした。 node.jsは非常に速く、特に並行性が高いです。なぜnode.jsがApacheよりもずっと遅いですか。

昨日、私はそれを誰かに見せたいと思っていました.... outch apache 2.4ははるかに高速でした。

セットアップ:

のNode.js(Express.js、ノード6.2.2)

const http = require('http'); 

const hostname = '127.0.0.1'; 
const port = 3000; 

const server = http.createServer((req, res) => { 
    res.statusCode = 200; 
    res.setHeader('Content-Type', 'text/plain'); 
    res.end('Hello World\n'); 
}); 

server.listen(port, hostname,() => { 
    console.log(`Server running at http://${hostname}:${port}/`); 
}); 

(PHPファイルを提供する)はApache 2.4

<?php 
    $foo = "Hello"; 
    $bar = "World"; 
    echo "$foo $bar"; 
?> 

私はApacheを開始しましたport 80 次に、ポート3000でnode.jsアプリケーションを起動し、Apache Benchmarkですべてをテストしました

ab -r -n 10000 -c 10 http://127.0.0.1/ 

結果:

Server Software:  Apache/2.4.18 
Server Hostname:  127.0.0.1 
Server Port:   80 

Document Path:  /
Document Length:  11 bytes 

Concurrency Level:  10 
Time taken for tests: 4.439 seconds 
Complete requests:  10000 
Failed requests:  0 
Total transferred:  1980000 bytes 
HTML transferred:  110000 bytes 
Requests per second: 2252.97 [#/sec] (mean) 
Time per request:  4.439 [ms] (mean) 
Time per request:  0.444 [ms] (mean, across all concurrent requests) 
Transfer rate:   435.63 [Kbytes/sec] received 

Connection Times (ms) 
       min mean[+/-sd] median max 
Connect:  0 1 1.3  0  12 
Processing:  1 3 1.8  3  88 
Waiting:  0 3 1.5  3  38 
Total:   1 4 1.8  4  91 

Percentage of the requests served within a certain time (ms) 
    50%  4 
    66%  4 
    75%  5 
    80%  5 
    90%  6 
    95%  7 
    98%  9 
    99%  10 
100%  91 (longest request) 

のNode.js

ab -r -n 10000 -c 10 http://127.0.0.1/ 

結果:

Server Software: 
Server Hostname:  127.0.0.1 
Server Port:   3000 

Document Path:  /
Document Length:  19 bytes 

Concurrency Level:  10 
Time taken for tests: 8.513 seconds 
Complete requests:  10000 
Failed requests:  0 
Non-2xx responses:  10000 
Total transferred:  4020000 bytes 
HTML transferred:  190000 bytes 
Requests per second: 1174.64 [#/sec] (mean) 
Time per request:  8.513 [ms] (mean) 
Time per request:  0.851 [ms] (mean, across all concurrent requests) 
Transfer rate:   461.14 [Kbytes/sec] received 

Connection Times (ms) 
       min mean[+/-sd] median max 
Connect:  0 0 0.3  0  7 
Processing:  1 8 4.4  8  69 
Waiting:  0 8 4.3  7  69 
Total:   2 8 4.4  8  69 

Percentage of the requests served within a certain time (ms) 
    50%  8 
    66%  9 
    75%  10 
    80%  10 
    90%  12 
    95%  15 
    98%  20 
    99%  23 
100%  69 (longest request) 

Iは、n = 1000をテストする場合、C = 100 ...同等以上 Apacheは常に2倍の速さです。

何か変更されましたか?彼らはApache 2.4を大幅に高速化しましたか?あるいはnode.jsが古くて遅くなったのですか?

私は本当にNode.jsのが

は私が間違っているアム...とすぐに5または10よりも高い同時実行があったとして速かったことを覚えていますか?コメントは感謝しています。

種類が マーティン

UPDATE

に関しては、私はそれらの結果を再現することはできませんウェブでhttp://zgadzaj.com/benchmarking-nodejs-basic-performance-tests-against-apache-php

を、この記事を見つけました。私が同じ設定をしようとすると、Apacheの方が高速です。

+2

これは、ノードとApacheについての主題と知識についての私の考えです。答えが正しいかどうかは分かりません。 ノードは、これらのすべての要求を処理するスレッドが1つだけなので、私はマルチスレッドであると信じているApacheに比べて設定、?しかし、さまざまなリクエスト(小さなものもあれば、中程度のものや重いもの)があれば、nodejsはすばらしい仕事に結びついていない、すばやくすべてのジョブを切り替えることができ、Apacheのスレッドが作業しています完成まで重労働?ちょっとした考え。 –

+0

@Stian私は全く同意します。おそらく、テストセットアップはnode.jsの利点を示すものではないでしょう。そのような場合、おそらくApacheはおそらく常に高速です... – marschro

答えて

3

2組の結果を見てください。 同じですか? ここには違いがあります: 2xx以外の応答:10000

テスト結果は同じではありませんので、パフォーマンスが固定されるまでは何も言えません。

関連する問題