mongodb 并发性能测试

之前做的一些mongodb的测试都是在exsi的两台虚拟间做的,由于虚拟机的问题,性能很不稳定。这两天正好有两台服务器空下来了,就用来跑了一下mongodb的并发测试。

服务器软硬件配置:

服务器:Dell PowerEdge R710

CPU: Intel Xeon E5530 2.4G X 2

硬盘:SAS 300G X 4 建立 Raid10

内存:16G

windows 2003 sp2 64位

mongodb 1.40 x64 for windows

mongodb在这台上跑,测试程序在另一台服务器上跑,两台服务器配置基本一样,除了硬盘(另一台是SAS 147G X4 Raid10)。

阅读全文

对之前写的java测试程序进行了更新,增加了一些参数和查询的测试:

http://farmerluo.googlecode.com/files/mongotest.rar

使用方法:

[root@web dist]# java -jar mongotest.jar
Usage:
mysql test:
java -jar mongotest.jar < mysql > < [select | update | insert] > < rows >  < host > < username > < password> 
mongo test:
java -jar mongotest.jar < mongo > < [select | update | insert] > < rows >  < host >

阅读全文

mongodb查询的语法

本文参考自官方的手册:

http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-ConditionalOperators%3A%3C%2C%3C%3D%2C%3E%2C%3E%3D

1 ) . 大于,小于,大于或等于,小于或等于

gt:大于 lt:小于 gte:大于或等于 lte:小于或等于

例子:

db.collection.find({ “field” : { gt: value } } ); // greater than : field > value
db.collection.find({ “field” : { lt: value } } ); // less than : field < value
db.collection.find({ “field” : { gte: value } } ); // greater than or equal to : field >= value
db.collection.find({ “field” : { lte: value } } ); // less than or equal to : field <= value

阅读全文

rpm包还是比较好管理和升级的,今天试着把mongodb 1.4.0做成rpm包。

网上的文章比较少,只有自己摸索着做了。

首先需要先做一些准备工作:

安装epel库,这一步可有可无。

wget http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm
rpm -ivh epel-release-5-3.noarch.rpm

阅读全文

最近写了个java的程序来测试mysql 与mongodb的性能,代码如下:

package mongotest;
import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import java.net.UnknownHostException;
import java.sql.*;

/**
*
* @author FarmerLuo
*/
public class Main {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
        // TODO code application logic here
        int rows = 0;
        long start = System.currentTimeMillis();

    //        try { Thread.sleep ( 3000 );
    //        } catch (InterruptedException ie){}

        if ( args.length < 2 ) {
            System.out.print("Lack parameter!!!n");
            System.exit(1);
        }

        if ( !args[0].equals("mysql") && !args[0].equals("mongo") ) {
            System.out.print("First parameter: mysql or mongon");
            System.exit(1);
        }

        if ( !args[1].equals("insert") && !args[1].equals("update") ) {
            System.out.print("Second parameter: insert or updaten");
            System.exit(2);
        }

        if ( args.length > 2 ) {
            rows = Integer.parseInt(args[2]);
        } else {
            rows = 10000;
        }

        if ( args[0].equals("mysql") ) {
            if ( args[1].equals("insert") ) {
                mysql_insert(rows);
            } else {
                mysql_update(rows);
            }
        } else {
            if ( args[1].equals("insert") ) {
                mongo_insert(rows);
            } else {
                mongo_update(rows);
            }
        }

        long stop = System.currentTimeMillis();
        long endtime = (stop - start)/1000;
        if ( endtime == 0 ) endtime = 1;
        long result = rows/endtime;

        System.out.print("Total run time:" + endtime + " secn");
        System.out.print("Total rows:" + rows + "n");
        System.out.print(args[0] + " " + args[1] + " Result:" + result + "row/secn"); 
    }

    public static void mysql_insert(long len) {

        Connection conn = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://192.168.20.24/test?user=root&password=1qaz2wsx&characterEncoding=UTF8");
            // Do something with the Connection
        } catch (SQLException ex) {
            // handle any errors
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
        }
        Statement stmt = null;
        try {
            stmt = conn.createStatement();
        } catch (SQLException ex) {
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
        }
        String str = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";

        //System.out.print(sql);
        for( int j = 0; j < len; j++ ){
            String sql = "insert into test (count, test1, test2, test3, test4) values (" + j + ",'" + str + "','" + str + "','" + str + "','" + str + "')";
            try {
                stmt.executeUpdate(sql);
            } catch (SQLException ex) {
                System.out.println("SQLException: " + ex.getMessage());
                System.out.println("SQLState: " + ex.getSQLState());
                System.out.println("VendorError: " + ex.getErrorCode());
            }
        }
    }


    public static void mysql_update(long len) {

        Connection conn = null;
        try {
            conn = DriverManager.getConnection("jdbc:mysql://192.168.20.24/test?user=root&password=1qaz2wsx&characterEncoding=UTF8");
            // Do something with the Connection
        } catch (SQLException ex) {
            // handle any errors
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
        }
        Statement stmt = null;
        try {
            stmt = conn.createStatement();
        } catch (SQLException ex) {
            System.out.println("SQLException: " + ex.getMessage());
            System.out.println("SQLState: " + ex.getSQLState());
            System.out.println("VendorError: " + ex.getErrorCode());
        }
        String str = "UPDATE7890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";

        //System.out.print(sql);
        for( int j = 0; j < len; j++ ){
            String sql = "update test set test1 = '" + str + "',test2 = '" + str + "' , test3 = '" + str + "', test4 = '" + str + "' where id = "+ j;
            try {
                stmt.executeUpdate(sql);
            } catch (SQLException ex) {
                System.out.println("SQLException: " + ex.getMessage());
                System.out.println("SQLState: " + ex.getSQLState());
                System.out.println("VendorError: " + ex.getErrorCode());
            }
        }
    }

    public static void mongo_insert(long len){
        Mongo m = null;
        try {
            m = new Mongo("192.168.20.24", 27017);
        } catch (UnknownHostException ex) {
            System.out.println("UnknownHostException:" + ex.getMessage());
        } catch (MongoException ex) {
            System.out.println("Mongo Exception:" + ex.getMessage());
            System.out.println("Mongo error code:" + ex.getCode());
        }

        DB db = m.getDB( "dbname6" );

        DBCollection dbcoll = db.getCollection("test");
        String str = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";
        for (int j = 0; j < len; j++) {
            DBObject dblist = new BasicDBObject();
            dblist.put("_id", j);
            dblist.put("count", j);
            dblist.put("test1", str);
            dblist.put("test2", str);
            dblist.put("test3", str);
            dblist.put("test4", str);
            try {
                dbcoll.insert(dblist);
            } catch (MongoException ex) {
                System.out.println("Mongo Exception:" + ex.getMessage());
                System.out.println("Mongo error code:" + ex.getCode());
            }
        }
    }

    public static void mongo_update(long len){
        Mongo m = null;
        try {
            m = new Mongo("192.168.20.24", 27017);
        } catch (UnknownHostException ex) {
            System.out.println("UnknownHostException:" + ex.getMessage());
        } catch (MongoException ex) {
            System.out.println("Mongo Exception:" + ex.getMessage());
            System.out.println("Mongo error code:" + ex.getCode());
        }

        DB db = m.getDB( "dbname6" );

        DBCollection dbcoll = db.getCollection("test");
        String str = "UPDATE7890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456";
        for (int j = 0; j < len; j++) {
            DBObject dblist = new BasicDBObject();
            DBObject qlist = new BasicDBObject();
            qlist.put("_id", j);
            dblist.put("test1", str);
            dblist.put("test2", str);
            dblist.put("test3", str);
            dblist.put("test4", str);
            try {
                dbcoll.update(qlist,dblist);
            } catch (MongoException ex) {
                System.out.println("Mongo Exception:" + ex.getMessage());
                System.out.println("Mongo error code:" + ex.getCode());
            }
        }
    }
}

阅读全文

作者的图片

阿辉

容器技术及容器集群等分布式系统研究

容器平台负责人

上海