mysql cluster使用到目前为止遇到渴望得到答案的问题,也是直接影响使用的问题就是mysql cluster的写入效率问题和cluster是否适合大数据存储、如何配置存储的问题。 在之前的测试中mysql cluster的写入效率一直不佳,这也是直接影响能否使用mysql cluster的
mysql cluster使用到目前为止遇到渴望得到答案的问题,也是直接影响使用的问题就是mysql cluster的写入效率问题和cluster是否适合大数据存储、如何配置存储的问题。
在之前的测试中mysql cluster的写入效率一直不佳,这也是直接影响能否使用mysql cluster的关键。现在我们来仔细测试一下。使用的环境略有变化。
data节点的内存扩展为4g。
集群配置如下:
[ndbd default]# options affecting ndbd processes on all data nodes:noofreplicas=2 # number of replicasdatamemory=2000m # how much memory to allocate for data storageindexmemory=300m # how much memory to allocate for index storage # for datamemory and indexmemory, we have used the # default values. since the world database takes up # only about 500kb, this should be more than enough for # this example cluster setup.maxnoofconcurrentoperations=1200000maxnooflocaloperations=1320000
测试代码如下:
/** * 向数据库中插入数据 * * @param conn * @param totalrowcount * @param perrowcount * @param tablename * @author lihzh(onecoder) * @throws sqlexception * @date 2013 -1 -17 下午1:57:10 */ private void insertdatatotable(connection conn, string tablename, long totalrowcount, long perrowcount, long startindex) throws sqlexception { conn.setautocommit( false); string sql = insert into + tablename + values(?,?,?); system. out.println( begin to prepare statement.); preparedstatement statement = conn.preparestatement(sql); long sum = 0l; for ( int j = 0; j 分下列情景进行写入测试。
数据加载、写入在内存中时,在独立的新库、新表中一次写入100,1000,10000,50000条记录,分别记录其耗时情况。(5次平均)
100:260ms 1000:1940ms 10000:17683ms(12000-17000) 50000: 93308、94730、90162、94849、162848
与普通单点mysql写入效率进行对比(2g内存)
100:182ms 1000:1624ms 10000:14946ms 50000:84438ms
双线程并发写入测试
由于只有两个sql节点,所以这里只采用双线程写入的方法进行测试。代码上采用了简单的硬编码
/** * 多线程并行写入测试 * * @author lihzh(onecoder) * @blog http://www.coderli.com * @date 2013 -2 -27 下午3:39:56 */ private void parallelinsert() { final long start = system. currenttimemillis(); thread t1 = new thread( new runnable() { @override public void run() { try { connection conn = getconnection(db_ipaddress, db_port, db_name, db_user, db_passowrd); mysqlclusterdatamachine datamachine = new mysqlclusterdatamachine(); datamachine.insertdatatotable(conn, table_name_datahouse, 500, 100, 0); long end1 = system.currenttimemillis(); system. out.println( thread 1 cost: + (end1 - start)); } catch (sqlexception e) { e.printstacktrace(); } } }); thread t2 = new thread( new runnable() { @override public void run() { try { connection conn = getconnection(db_ipaddress_two, db_port, db_name, db_user, db_passowrd); mysqlclusterdatamachine datamachine = new mysqlclusterdatamachine(); datamachine.insertdatatotable(conn, table_name_datahouse, 500, 100, 500); long end2 = system.currenttimemillis(); system. out.println( thread 2 cost: + (end2 - start)); } catch (sqlexception e) { e.printstacktrace(); } } }); t1.start(); t2.start(); }
测试结果:
(总条数/每次) 线程1(总/平均- 各写一半数据) 线程2 并行总耗时 单线程单点
1000/100 985/197 1005/201 1005/201 2264/226
10000/1000 9223/1836 9297/1850 9297/1850 19405/1940
100000/10000 121425/12136 122081/12201 121425/12136 148518/14851
从结果可以看出,在10000条以下批量写入的情况下,sql节点的处理能力是集群的瓶颈,双线程双sql写入相较单线程单节点效率可提升一倍。但是当批量写入数据达到一定数量级,这种效率的提升就不那么明显了,应该是集群中的其他位置也产生了瓶颈。
注:由于各自测试环境的差异,测试数据仅可做内部比较,不可外部横向对比。仅供参考。
写入测试,要做的还很多,不过暂时告一段落。大数据存储和查询测试,随后进行。
原文地址:mysql cluster写入效率测试, 感谢原作者分享。