最近公司弄了一台dell pe r710来做数据库,里面配了4块Intel® X25-E 64G的固态硬盘,正好还有另外两台数据库服务器也是dell pe r710的,配置基本一样,只是硬盘配的是SAS 300G,15K转的SAS硬盘。我正好趁这个机会,对两台服务器的磁盘做了一次测试:
Intel X25-E 64G X 4 做 Raid 5
VS
SAS 300G X 4 做Raid 10
最近公司弄了一台dell pe r710来做数据库,里面配了4块Intel® X25-E 64G的固态硬盘,正好还有另外两台数据库服务器也是dell pe r710的,配置基本一样,只是硬盘配的是SAS 300G,15K转的SAS硬盘。我正好趁这个机会,对两台服务器的磁盘做了一次测试:
Intel X25-E 64G X 4 做 Raid 5
VS
SAS 300G X 4 做Raid 10
对之前写的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 >
本文参考自官方的手册:
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
iostat
iostat用于输出CPU和磁盘I/O相关的统计信息. 命令格式:
iostat [ -c | -d ] [ -k | -m ] [ -t ] [ -V ] [ -x ] [ device [ … ] | ALL ] [ -p [ device | ALL ] ]
[ interval [ count ] ]
1)iostat的 简单使用
iostat可以显示CPU和I/O系统的负载情况及分区状态信息. 直接执行iostat可以显示下面内容:
最近写了个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());
}
}
}
}
redis有一个类似mysql 高级复制的功能,可以让一台主redis上的数据实时同步到一台备redis上。
主redis:192.168.20.23
备redis:192.168.20.24
我们先看主redis上有哪些key: