MongoDB的简单QPS测试(单机)

16 篇文章 0 订阅

mongoDB官方网站下载:

1、mongodb-linux-i686-2.2.1.tgz

2、java驱动 mongo-2.2.jar

测试服务器为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万条记录:

/usr/sbin/ab -n 1000 -c 400 http://192.168.175.130:8080/labWeb/insertMongodb.do?insertNum=1000

监控:bin/mongostat

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常抱歉,我误解了你的问题。在一个16c32g的服务器上,部署MongoDBQPS限制也取决于多个因素,比如硬件配置、数据结构、查询类型和索引等等。 一般来说,在一个16c32g的服务器上,MongoDBQPS限制可以达到数万到数十万的范围。但是,具体的QPS限制取决于多个因素,例如: 1. 硬件配置:在一个16c32g的服务器上,硬件配置越高,MongoDB的性能就越好。比如,更快的CPU、更大的内存、更快的磁盘等等,都可以提高MongoDB的性能。 2. 数据结构和索引:MongoDB支持多种数据结构和索引类型,不同的数据结构和索引类型对性能有不同的影响。需要根据实际需求来选择合适的数据结构和索引类型。 3. 查询类型:MongoDB支持多种查询类型,例如简单查询、聚合查询、地理位置查询等等。不同的查询类型对性能有不同的影响。 4. 网络延迟:MongoDB的性能还受到网络延迟的影响。网络延迟越高,MongoDB的性能就越差。 因此,无法给出一个具体的QPS限制。但是,在一个16c32g的服务器上,MongoDB的性能应该能够满足大多数应用的需求。如果需要进一步提高MongoDB的性能,可以采取以下措施: 1. 使用合适的硬件配置:可以使用更快的CPU、更大的内存、更快的磁盘等等来提高MongoDB的性能。 2. 选择合适的数据结构和索引类型:根据实际需求来选择合适的数据结构和索引类型,以便提高查询性能。 3. 优化查询语句:可以优化查询语句,避免全表扫描等操作,提高查询性能。 总之,在一个16c32g的服务器上,MongoDBQPS限制取决于多个因素,需要根据实际需求和硬件配置来进行具体的优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值