Advertisement
Guest User

Node.JS Cluster vs JXCore Multithreaded vs HHVM

a guest
Sep 10th, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.33 KB | None | 0 0
  1. ##################################################################
  2. Node cluster:
  3. Node version: v0.10.25
  4.  
  5. Code:
  6. var http = require('http');
  7. var mysql = require('mysql2');
  8. var async = require('async');
  9. var connection = mysql.createConnection({ user: 'benchmark', database: 'benchmark', password: 'benchpass'});
  10. var cluster = require('cluster');
  11. var numCPUs = require('os').cpus().length;
  12.  
  13. if (cluster.isMaster) {
  14. // Fork workers.
  15. for (var i = 0; i < numCPUs; i++) {
  16. cluster.fork();
  17. }
  18.  
  19. cluster.on('exit', function (worker, code, signal) {
  20. console.log('worker ' + worker.process.pid + ' died');
  21. });
  22. } else {
  23. http.createServer(function (req, res) {
  24. res.writeHead(200, {'Content-Type': 'text/html'});
  25. connection.query('SELECT * FROM users;', function (err, rows) {
  26. if (err) {
  27. throw new SQLException('Connection failed: ' + err);
  28. }
  29. var table = '<table><tr><th>id</th><th>username</th><th>password</th><th>banking account</th><th>phone number</th></tr>';
  30. async.forEach(rows, function (row, callback) {
  31. table += '<tr><td>' + row.id + '</td><td>' + row.username + '</td><td>' + row.password + '</td><td>' + row.banking_account + '</td><td>' + row.phone_number + '</td></tr>';
  32. callback();
  33. }, function (err) {
  34. if (err) {
  35. throw new Error('Async failed! ' + err);
  36. }
  37. table += '</table>';
  38. table += '<div style="color:red">Hello from cluster worker: ' + cluster.worker.id + '</div>';
  39. res.end(table);
  40. });
  41. });
  42. }).listen(9615);
  43. console.log("Server running at http://localhost:9615 on cluster worker number " + cluster.worker.id);
  44. }
  45.  
  46. Run command:
  47. /srv/node/benchmark-node-cluster$ NODE_DEBUG=cluster node index.js
  48. 20280,Master Worker 20286 online
  49. 20280,Master Worker 20287 online
  50. 20280,Master Worker 20289 online
  51. 20280,Master Worker 20290 online
  52. Server running at http://localhost:9615 on cluster worker number 1
  53. Server running at http://localhost:9615 on cluster worker number 2
  54. Server running at http://localhost:9615 on cluster worker number 3
  55. Server running at http://localhost:9615 on cluster worker number 4
  56.  
  57. Benchmark:
  58. ab -n 100000 -c 200 http://127.0.0.1:9615/
  59. This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
  60. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  61. Licensed to The Apache Software Foundation, http://www.apache.org/
  62.  
  63. Benchmarking 127.0.0.1 (be patient)
  64. Completed 10000 requests
  65. Completed 20000 requests
  66. Completed 30000 requests
  67. Completed 40000 requests
  68. Completed 50000 requests
  69. Completed 60000 requests
  70. Completed 70000 requests
  71. Completed 80000 requests
  72. Completed 90000 requests
  73. Completed 100000 requests
  74. Finished 100000 requests
  75.  
  76.  
  77. Server Software:
  78. Server Hostname: 127.0.0.1
  79. Server Port: 9615
  80.  
  81. Document Path: /
  82. Document Length: 11001 bytes
  83.  
  84. Concurrency Level: 200
  85. Time taken for tests: 11.692 seconds
  86. Complete requests: 100000
  87. Failed requests: 0
  88. Total transferred: 1110100000 bytes
  89. HTML transferred: 1100100000 bytes
  90. Requests per second: 8553.03 [#/sec] (mean)
  91. Time per request: 23.384 [ms] (mean)
  92. Time per request: 0.117 [ms] (mean, across all concurrent requests)
  93. Transfer rate: 92721.84 [Kbytes/sec] received
  94.  
  95. Connection Times (ms)
  96. min mean[+/-sd] median max
  97. Connect: 0 0 0.1 0 3
  98. Processing: 0 23 16.8 20 113
  99. Waiting: 0 23 16.8 20 113
  100. Total: 0 23 16.8 20 113
  101.  
  102. Percentage of the requests served within a certain time (ms)
  103. 50% 20
  104. 66% 28
  105. 75% 34
  106. 80% 37
  107. 90% 45
  108. 95% 52
  109. 98% 63
  110. 99% 80
  111. 100% 113 (longest request)
  112.  
  113.  
  114. ##########################################################################
  115. JXCore multithreaded
  116. JXCore version: JXcore Beta 2.3.2
  117.  
  118. Code:
  119. var http = require('http');
  120. var mysql = require('mysql2');
  121. var async = require('async');
  122. var connection = mysql.createConnection({ user: 'benchmark', database: 'benchmark', password: 'benchpass'});
  123.  
  124. http.createServer(function (req, res) {
  125. res.writeHead(200, {'Content-Type': 'text/html'});
  126. connection.query('SELECT * FROM users;', function (err, rows) {
  127. if (err) {
  128. throw new SQLException('Connection failed: ' + err);
  129. }
  130. var table = '<table><tr><th>id</th><th>username</th><th>password</th><th>banking account</th><th>phone number</th></tr>';
  131. async.forEach(rows, function (row, callback) {
  132. table += '<tr><td>' + row.id + '</td><td>' + row.username + '</td><td>' + row.password + '</td><td>' + row.banking_account + '</td><td>' + row.phone_number + '</td></tr>';
  133. callback();
  134. }, function (err) {
  135. if (err) {
  136. throw new Error('Async failed! ' + err);
  137. }
  138. table += '</table>';
  139. table += '<div style="color:red">Hello from jxcore thread: ' + process.threadId + '</div>';
  140. res.end(table);
  141. });
  142. });
  143. }).listen(9615);
  144. console.log("Server running at http://localhost:9615 on thread number " + process.threadId);
  145.  
  146. Run command:
  147. /srv/node/benchmark-jxcore$ jx mt-keep:4 index.js
  148. Server running at http://localhost:9615 on thread number 0
  149. Server running at http://localhost:9615 on thread number 1
  150. Server running at http://localhost:9615 on thread number 2
  151. Server running at http://localhost:9615 on thread number 3
  152.  
  153. Benchmark:
  154. ab -n 100000 -c 200 http://127.0.0.1:9615/
  155. This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
  156. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  157. Licensed to The Apache Software Foundation, http://www.apache.org/
  158.  
  159. Benchmarking 127.0.0.1 (be patient)
  160. Completed 10000 requests
  161. Completed 20000 requests
  162. Completed 30000 requests
  163. Completed 40000 requests
  164. Completed 50000 requests
  165. Completed 60000 requests
  166. Completed 70000 requests
  167. Completed 80000 requests
  168. Completed 90000 requests
  169. Completed 100000 requests
  170. Finished 100000 requests
  171.  
  172.  
  173. Server Software:
  174. Server Hostname: 127.0.0.1
  175. Server Port: 9615
  176.  
  177. Document Path: /
  178. Document Length: 11000 bytes
  179.  
  180. Concurrency Level: 200
  181. Time taken for tests: 14.994 seconds
  182. Complete requests: 100000
  183. Failed requests: 0
  184. Total transferred: 1110000000 bytes
  185. HTML transferred: 1100000000 bytes
  186. Requests per second: 6669.12 [#/sec] (mean)
  187. Time per request: 29.989 [ms] (mean)
  188. Time per request: 0.150 [ms] (mean, across all concurrent requests)
  189. Transfer rate: 72292.19 [Kbytes/sec] received
  190.  
  191. Connection Times (ms)
  192. min mean[+/-sd] median max
  193. Connect: 0 0 20.5 0 999
  194. Processing: 0 30 22.8 25 234
  195. Waiting: 0 29 22.8 25 234
  196. Total: 0 30 30.7 25 1037
  197.  
  198. Percentage of the requests served within a certain time (ms)
  199. 50% 25
  200. 66% 35
  201. 75% 41
  202. 80% 46
  203. 90% 60
  204. 95% 71
  205. 98% 90
  206. 99% 101
  207. 100% 1037 (longest request)
  208.  
  209. ###########################################################################
  210. JXCore running Cluster code with no MT
  211.  
  212. ab -n 100000 -c 200 http://127.0.0.1:9615/
  213. This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
  214. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  215. Licensed to The Apache Software Foundation, http://www.apache.org/
  216.  
  217. Benchmarking 127.0.0.1 (be patient)
  218. Completed 10000 requests
  219. Completed 20000 requests
  220. Completed 30000 requests
  221. Completed 40000 requests
  222. Completed 50000 requests
  223. Completed 60000 requests
  224. Completed 70000 requests
  225. Completed 80000 requests
  226. Completed 90000 requests
  227. Completed 100000 requests
  228. Finished 100000 requests
  229.  
  230.  
  231. Server Software:
  232. Server Hostname: 127.0.0.1
  233. Server Port: 9615
  234.  
  235. Document Path: /
  236. Document Length: 11001 bytes
  237.  
  238. Concurrency Level: 200
  239. Time taken for tests: 14.254 seconds
  240. Complete requests: 100000
  241. Failed requests: 0
  242. Total transferred: 1110100000 bytes
  243. HTML transferred: 1100100000 bytes
  244. Requests per second: 7015.81 [#/sec] (mean)
  245. Time per request: 28.507 [ms] (mean)
  246. Time per request: 0.143 [ms] (mean, across all concurrent requests)
  247. Transfer rate: 76057.18 [Kbytes/sec] received
  248.  
  249. Connection Times (ms)
  250. min mean[+/-sd] median max
  251. Connect: 0 0 18.1 0 997
  252. Processing: 0 28 24.5 22 171
  253. Waiting: 0 28 24.5 22 171
  254. Total: 0 28 30.6 22 1044
  255.  
  256. Percentage of the requests served within a certain time (ms)
  257. 50% 22
  258. 66% 35
  259. 75% 42
  260. 80% 47
  261. 90% 59
  262. 95% 72
  263. 98% 91
  264. 99% 104
  265. 100% 1044 (longest request)
  266.  
  267.  
  268. ###########################################################################
  269. HHVM fastCGI + Nginx
  270. HHVM version:
  271. HipHop VM 3.2.0 (rel)
  272. Compiler: tags/HHVM-3.2.0-0-g01228273b8cf709aacbd3df1c51b1e690ecebac8
  273. Repo schema: c52ba40f4a246d35a88f1dfc1daf959851ced8aa
  274.  
  275. Code:
  276. <?php
  277.  
  278. $db = new PDO('mysql:host=localhost;dbname=benchmark', 'benchmark', 'benchpass');
  279. $results = $db->query('SELECT * FROM users;');
  280.  
  281. echo '<table><tr><th>id</th><th>username</th><th>password</th><th>banking account</th><th>phone number</th></tr>';
  282. foreach ($results as $row) {
  283. echo '<tr><td>' . $row['id'] . '</td><td>' . $row['username'] . '</td><td>' . $row['password'] . '</td><td>' . $row['banking_account'] . '</td><td>' . $row['phone_number'] . '</td></tr>';
  284. }
  285. echo '</table>';
  286. echo '<div style="color:red">Hello from HHVM!</div>';
  287.  
  288.  
  289.  
  290. Benchmark:
  291. ab -n 100000 -c 200 http://127.0.0.1:8080/
  292. This is ApacheBench, Version 2.3 <$Revision: 1528965 $>
  293. Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
  294. Licensed to The Apache Software Foundation, http://www.apache.org/
  295.  
  296. Benchmarking 127.0.0.1 (be patient)
  297. Completed 10000 requests
  298. Completed 20000 requests
  299. Completed 30000 requests
  300. Completed 40000 requests
  301. Completed 50000 requests
  302. Completed 60000 requests
  303. Completed 70000 requests
  304. Completed 80000 requests
  305. Completed 90000 requests
  306. Completed 100000 requests
  307. Finished 100000 requests
  308.  
  309.  
  310. Server Software: nginx/1.6.1
  311. Server Hostname: 127.0.0.1
  312. Server Port: 8080
  313.  
  314. Document Path: /
  315. Document Length: 10989 bytes
  316.  
  317. Concurrency Level: 200
  318. Time taken for tests: 16.247 seconds
  319. Complete requests: 100000
  320. Failed requests: 0
  321. Total transferred: 1115100000 bytes
  322. HTML transferred: 1098900000 bytes
  323. Requests per second: 6155.01 [#/sec] (mean)
  324. Time per request: 32.494 [ms] (mean)
  325. Time per request: 0.162 [ms] (mean, across all concurrent requests)
  326. Transfer rate: 67025.92 [Kbytes/sec] received
  327.  
  328. Connection Times (ms)
  329. min mean[+/-sd] median max
  330. Connect: 0 5 70.4 0 1000
  331. Processing: 2 27 8.0 26 237
  332. Waiting: 2 27 8.0 26 237
  333. Total: 4 32 70.8 26 1036
  334.  
  335. Percentage of the requests served within a certain time (ms)
  336. 50% 26
  337. 66% 31
  338. 75% 33
  339. 80% 33
  340. 90% 35
  341. 95% 39
  342. 98% 43
  343. 99% 48
  344. 100% 1036 (longest request)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement