试用Cassandra,其写效率太差

Cassandra是由Facebook贡献的开源分布式数据库。其遵从NoSql理念,是结合了Dynamo与BigTable的产物。最近Twitter和Digg都将其数据库由MySql迁往Cassandra。看到其发展势头不错,我就下载下来,做了个测试。

测试环境:

分别在两台机器上部署cassandra.这里说明下关键配置:
配置文件路径是%Cassandra_Home%\conf\storage-conf.xml

<Storage>
<!--两台机器的ClusterName必须相同,作为集群标识 -->
<ClusterName>BurceServers</ClusterName>
<AutoBootstrap>false</AutoBootstrap>

<Keyspaces>
<Keyspace Name="Keyspace1">
<KeysCachedFraction>0.01</KeysCachedFraction>
<ColumnFamily CompareWith="BytesType" Name="Standard1"/>
<ColumnFamily CompareWith="UTF8Type" Name="Standard2"/>
<ColumnFamily CompareWith="TimeUUIDType" Name="StandardByUUID1"/>
<ColumnFamily ColumnType="Super"
CompareWith="UTF8Type"
CompareSubcolumnsWith="UTF8Type"
Name="Super1"
Comment="A column family with supercolumns, whose column and subcolumn names are UTF8 strings"/>
</Keyspace>
</Keyspaces>

<Partitioner>org.apache.cassandra.dht.RandomPartitioner</Partitioner>

<InitialToken></InitialToken>

<EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>

<ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>

<ReplicationFactor>1</ReplicationFactor>

<CommitLogDirectory>c:/cassandra/lib/cassandra/commitlog</CommitLogDirectory>
<DataFileDirectories>
<DataFileDirectory>c:/cassandra/lib/cassandra/data</DataFileDirectory>
</DataFileDirectories>
<CalloutLocation>c:/cassandra/lib/cassandra/callouts</CalloutLocation>
<StagingFileDirectory>c:/cassandra/lib/cassandra/staging</StagingFileDirectory>

<!--在这里可以添加多个cassandra服务器-->
<Seeds>
<Seed>10.219.101.101</Seed>
<Seed>10.219.101.121</Seed>
</Seeds>


<RpcTimeoutInMillis>5000</RpcTimeoutInMillis>
<CommitLogRotationThresholdInMB>128</CommitLogRotationThresholdInMB>

<!--监听地址必须是本机IP-->
<ListenAddress>10.219.101.101</ListenAddress>
<StoragePort>7000</StoragePort>
<ControlPort>7001</ControlPort>
<!--基于Thrift的cassandra客户端监听地址-->
<ThriftAddress>10.219.101.101</ThriftAddress>
<ThriftPort>9160</ThriftPort>
<ThriftFramedTransport>false</ThriftFramedTransport>


<SlicedBufferSizeInKB>64</SlicedBufferSizeInKB>

<ColumnIndexSizeInKB>64</ColumnIndexSizeInKB>

<MemtableSizeInMB>64</MemtableSizeInMB>

<MemtableObjectCountInMillions>0.1</MemtableObjectCountInMillions>
<MemtableFlushAfterMinutes>60</MemtableFlushAfterMinutes>

<ConcurrentReads>8</ConcurrentReads>
<ConcurrentWrites>32</ConcurrentWrites>

<CommitLogSync>periodic</CommitLogSync>
<CommitLogSyncPeriodInMS>10000</CommitLogSyncPeriodInMS>
<GCGraceSeconds>864000</GCGraceSeconds>
<BinaryMemtableSizeInMB>256</BinaryMemtableSizeInMB>

</Storage>


除增加了一个cassandra的服务器外,基本采用默认配置。

测试代码:


/**
*
*/
package com.tpri.sis.test;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;

import me.prettyprint.cassandra.service.CassandraClient;

import org.apache.cassandra.service.Cassandra;
import org.apache.cassandra.service.ColumnPath;
import org.apache.cassandra.service.ConsistencyLevel;
import org.apache.cassandra.service.InvalidRequestException;
import org.apache.cassandra.service.TimedOutException;
import org.apache.cassandra.service.UnavailableException;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
import org.apache.thrift.transport.TTransportException;

/**
* @author brucepang
*
*/
public class CassandraClientDemo {

/**
*
*/
public CassandraClientDemo() {

}

/**
* @param args
*/
public static void main(String[] args) {

try {
TTransport tr = new TSocket("10.219.101.101", 9160);

TProtocol pro = new TBinaryProtocol(tr);
Cassandra.Client cli = new Cassandra.Client(pro);
tr.open();

String key = null;
String name, age;
ColumnPath namePath = new ColumnPath("Standard1", null, "name"
.getBytes("UTF-8"));
ColumnPath agePath = new ColumnPath("Standard1", null, "age"
.getBytes("UTF-8"));

String keySpace = "Keyspace1";
long time = 0;
long l1 = System.currentTimeMillis();
for (int i = 0; i < 100; i++) {
key = String.valueOf(i);
name = RandomStringUtils.random(5,"abcdefghefsdf");
time = System.currentTimeMillis();
cli.insert(keySpace, key, namePath, name.getBytes("UTF-8"),
time, ConsistencyLevel.ONE);
cli.insert(keySpace, key, agePath, key.getBytes("UTF-8"), time,
ConsistencyLevel.ONE);
}
long l2 = System.currentTimeMillis();
long ch = l2 - l1;
System.out.println(ch);

} catch (TTransportException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidRequestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TimedOutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}





测试结果:1 写100条数据,耗时59922毫秒,将近1分钟;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值