Created
August 3, 2011 22:32
-
-
Save addisonj/1124008 to your computer and use it in GitHub Desktop.
Just a little benchmark... but its not working
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
CONFIG = require('./config'), | |
Client = require('mysql').Client, | |
fs = require('fs'), | |
client = new Client(CONFIG), | |
TEST_DB = 'node_test', | |
TEST_TABLE = 'test', | |
count = 0; | |
client.connect(); | |
client.query('CREATE DATABASE ' + TEST_DB, function(err) { | |
if (err && err.number !== Client.ERROR_DB_CREATE_EXISTS) { | |
throw err; | |
} | |
}); | |
client.query('USE ' + TEST_DB); | |
client.query( | |
'CREATE TABLE '+ TEST_TABLE+ | |
'(id INT(11) AUTO_INCREMENT, '+ | |
'title VARCHAR(255), '+ | |
'text TEXT, '+ | |
'created DATETIME, '+ | |
'PRIMARY KEY (id))' | |
); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
client.query( | |
'INSERT INTO ' + TEST_TABLE + ' ' + | |
'SET title = ?, text = ?, created = ?', | |
['TEST' + count++, Math.random(), new Date().toUTCString()]); | |
fs.readFile('./data', function(err, data) { | |
if (err) throw err; | |
res.end(data); | |
}); | |
}).listen(3000); | |
console.log('Server running on port 3000'); | |
/* running 'ab -r -n 100000 -c 1000 http://127.0.0.1:3000/' results in | |
Error: EMFILE, Too many open files './data' | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment