@SuppressWarnings("serial")
public class MyServlet extends HttpServlet {
Logger logger = Logger.getLogger(this.getClass());
Session s = new Session("localhost",5984);
Database db = s.getDatabase("testdb");
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
String id = req.getPathInfo().substring(1);
PrintWriter out = res.getWriter();
Document doc = db.getDocument(id);
if (doc==null){
res.setContentType("text/plain");
out.println("Error: no document with id " + id +" found.");
} else {
res.setContentType("application/json");
out.println(doc.getJSONObject());
}
out.close();
}
}
结果
Concurrent Requests Average Response time (ms) Requests/second
10 23 422
50 119 416
100 243 408
150 363 411
Node
var http = require ('http'),
url = require('url'),
cradle = require('cradle'),
c = new(cradle.Connection)(
'127.0.0.1',5984,{cache: false, raw: false}),
db = c.database('testdb'),
port=8081;
process.on('uncaughtException', function (err) {
console.log('Caught exception: ' + err);
});
http.createServer(function(req,res) {
var id = url.parse(req.url).pathname.substring(1);
db.get(id,function(err, doc) {
if (err) {
console.log('Error'+err.message);
res.writeHead(500,{'Content-Type': 'text/plain'});
res.write('Error' + err.message);
res.end();
} else {
res.writeHead(200,{'Content-Type': 'application/json'});
res.write(JSON.stringify(doc));
res.end();
}
});
}).listen(port);
结果:
Concurrent Requests Average Response time (ms) Requests/second