13. 13 גלעד ע"י נכתבשהם
shoham.gilad@gmail.com
:'ב נספחNode.js vs PHPעומסים מבחן
בין השוואה בוצעה הבא בניסויNode.jsלביןPHP(Apache2ו–(mod_phpשזוהי כיוון ,כך בוצעה ההשוואה .
ב בשימוש ביותר הנפוצה הארכיטקטורה-PHPב שימוש ידי על יותר טובים ביצועים לקבל שניתן )שבצדק (ייתכן שיגידו יש .
Nginx or LighthttpdכשרתHTTPעבורPHPדבר של בסופו .PHPזה ואין ,ונפרדים רבים בתהליכים רץ השרת בצד
( אותם שיצרה המכניקה מה משנהmod_phpאוfastcgiמכניקה אולארכיטקטורה ניצמד ההשוואה לשם לכן .)אחרת
.הנפוצה
הניסוי סביבת
הניסוי לצורךנכתבהב פשוטה אפליקציה–java scriptוב–php5שולפת האפליקציה .50מ שורות–wordpress
)פתוח בקוד בלוגים (סביבתבצורת החוצה המידע את ומייצאתjsonלא שאנו כיוון היא פשוטה שהאפליקציה לכך הסיבה .
העיקרית שהמטרה וכן ,השפות בין מימוש להבדלי להיכנס רוציםהיאלהשוותהארכיטקטורה אתביןהפיתוח טכנולוגיותולא
.הקוד איכות את
חומרה:
:הבא המפרט בעל וירטואלי שרת
1 x Core Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz
2 Gb RAM.
OS is 64 Bit Ubuntu 12.10 installed fresh before running these tests.
We installed the Load Impact Server metric agent.
תוכנה:
Apache/2.2.22 and
PHP 5.4.6.
Node.js version 0.8.18 (built using this script)
MySQL is version 5.5.29.
The data table in the tests is the options table from a random WordPress blog.
14. 14 גלעד ע"י נכתבשהם
shoham.gilad@gmail.com
:שרצו הקוד קטעי
// Include http module,
var http = require('http'),
mysql = require("mysql");
// Create the connection.
// Data is default to new mysql installation and should be changed according to your
configuration.
var connection = mysql.createConnection({
user: "wp",
password: "****",
database: "random"
});
// Create the http server.
http.createServer(function (request, response) {
// Attach listener on end event.
request.on('end', function () {
// Query the database.
connection.query('SELECT * FROM wp_options limit 50;', function (error, rows,
fields) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
// Send data as JSON string.
// Rows variable holds the result of the query.
response.end(JSON.stringify(rows));
});
});
// Listen on the 8080 port.
}).listen(8080);
<!--?php $db = new PDO('mysql:host=localhost;dbname=*****', 'wp', '*****'); $all= $db--->query('SELECT *
FROM wp_options limit 50;')->fetchAll();
echo json_encode($all);