一直好奇于MongoDB的读写速度以及它的特有的NoSQL查询机制。有幸作了一次Sybase ASA(SQLAnywhere12)和MongoDB写入数据行的速度的比较。这对于大规模Web访问来说,非常重要。
比较基准:写入100000行,每行三列,id(整数), name varchar(32), col_blob或clob,8K左右长度。比较最终的写入时间。
1. ASA12:
dbinit.exe bench.db
dbeng12.exe bench.db
代码如下:
package com.sql9;import java.sql.*;
import java.util.Properties;
public class Bench4SQLAnywhere
{
// prepare about 100000 rows of data
// (id, name, col_clob)
// e.g. (1, "wang", "abcdef12345555555555555555555555555555555555555555555....")
// the col_blob should be 8K or longer.
// dsn: benchASA
public static final String DSN = "bench_ASA";
public static final String url = "jdbc:sqlanywhere:UserID=dba;Password=sql;Server=bench;DBN=bench";
public static void testWrite()
{
Connection conn = null;
System.out.println("begin time: " + new Timestamp(new java.util.Date().getTime()));
// System.setProperty("java.library.path", "v:/target/ASA120/Bin32");
try
{
Properties props = new Properties();
props.put("DYNAMIC_PREPARE", true);
conn = DriverManager.getConnection("jdbc:sqlanywhere:DSN=" + DSN + ";uid=dba;pwd=sql", props);
// conn = DriverManager.getConnection(url, props);
Statement stmt = conn.createStatement();
stmt.executeUpdate("create table t(id int primary key, name varchar(32) null, col_blob long varchar null)");
stmt.close();
stmt = null;
PreparedStatement pstmt = conn.prepareStatement("insert into t values(?, ?, ?)");
StringBuilder sb = new StringBuilder(8000);
for (int i=0; i<800; i++)
{
sb.append("abcde12345");
}
for (int i=0; i<100000; i++)
{
pstmt.setInt(1, i+1);
pstmt.setString(2, "wang " + i);
pstmt.setString(3, sb.toString());
pstmt.executeUpdate();
if ((i+1) % 1000 == 0)
{
conn.commit();
}
}
conn.commit();
pstmt.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
// if conn not null, just drop the table ????
}
System.out.println("end time: " + new Timestamp(new java.util.Date().getTime()));
try
{
if (conn != null)
{
Statement stmt = conn.createStatement();
stmt.executeUpdate("drop table t");
stmt.close();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close();
}
catch (Exception ex2) {}
}
}
}
/**
* @param args
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
testWrite();
}
/**
* result
* begin time: 2012-04-12 17:44:22.292
end time: 2012-04-12 17:55:16.971
*/
}
我们可以看到最终结果: begin time: 2012-04-12 17:44:22.292
end time: 2012-04-12 17:55:16.971, 大概花了11分钟。是够慢的。
运行时需要指定-Djava.library.path=<asa12>/bin32目录。ORA-14551: 无法在查询中执行 DML 操作 解决方法OCM考试中Dataguar的配置相关资讯 MongoDB
- MongoDB 3.3.0 发布下载 (01月14日)
- 使用MongoDB C#官方驱动操作 (12/31/2015 16:27:56)
- CentOS 6.6下安装MongoDB 3.0.1 (12/21/2015 19:29:02)
| - MongoDB 3.2版WiredTiger存储引擎 (01月02日)
- 进程监控工具Supervisor 启动 (12/26/2015 10:49:57)
- MongoDB 3.2.1 RC0 发布下载 (12/18/2015 11:32:29)
|
本文评论 查看全部评论 (0)