mysql mongodb qps_MongoDB的简单QPS测试(单机)

本文介绍了在Dell E5410 Debian Linux服务器上进行的MongoDB QPS测试。使用Apache Bench作为打压工具,MongoDB Manager和InsertMongodbServlet进行数据插入操作,通过监控工具mongostat观察,在400个并发线程下,成功插入100万条记录,达到约28000的QPS。测试结果显示MongoDB在单机高并发场景下的强大性能。
摘要由CSDN通过智能技术生成

mongoDB官方网站下载:

测试服务器为Dell  E5410 的Debian linux 2.6,配置为:

1、4核,2.33GHz

2、内存3G

3、SATA硬盘2T

web服务器:tomcat5.5

打压工具:Apache Bench

监控工具:mongostat

测试思路:

1、因为MongoDB内置了连接池,所以客户端程序相对简单,只需从一个Mongo的单例获取连接即可;

2、每个请求做1000次插入;

测试代码MongoDBManager:

public class MongoDBManager {

static private MongoDBManager instance; // 唯一实例

//public static final String DB_NAME = "lab";

// public static final String MESSAGE_COLLECTION = "email";

static synchronized public MongoDBManager getInstance(final String ip, int port, int poolSize) throws UnknownHostException {

if (instance == null) {

instance = new MongoDBManager(ip,port,poolSize);

}

return instance;

}

private MongoDBManager() {

}

private MongoDBManager(final String ip, int port, int poolSize) throws UnknownHostException {

init(ip,port,poolSize);

}

public DB getDB(String dbname) {

return mongo.getDB(dbname);

}

private Mongo mongo;

public void init(final String ip, int port, int poolSize)

throws java.net.UnknownHostException {

System.setProperty("MONGO.POOLSIZE", String.valueOf(poolSize));

if (mongo == null) {

MongoOptions options = new MongoOptions();

options.autoConnectRetry = true;

options.connectionsPerHost = poolSize;

ServerAddress serverAddress = new ServerAddress(ip, port);

mongo = new Mongo(serverAddress, options);

}

}

}

测试代码InsertMongodbServlet:

public class InsertMongodbServlet extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

Integer insertNum = Integer.valueOf(req.getParameter("insertNum")

.toString());

resp.setContentType("text/html;charset=UTF-8");

resp.setHeader("Cache-Control", "no-cache");

DB db = MongoDBManager.getInstance("127.0.0.1", 27017, 500)

.getDB("lab");

DBCollection tests = db.getCollection("tests");

for (int i = 0; i < insertNum; i++) {

DBObject test = new BasicDBObject();

test.put("id", 10000);

test.put("name", "This is for mongodb insert.");

tests.insert(test);

}

resp.getWriter().write(" Insert mongodb successed!");

}

public void doPost(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

}

}

开始压力测试,开1000个线程,共插入100万条记录:

监控:bin/mongostat

dcc718bd-8ab7-3d8a-ac9a-8f15046f2a86.png

可以看到在400个并发情况下,插入100万记录,QPS在28000左右。

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2012-11-07 10:16

浏览 2291

分类:数据库

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值