我安装了一个 3 节点 Cassandra (2.0.3) 集群,这是我的表:
CREATE TABLE user (
id text,
phone text,
name text,
email text,
PRIMARY KEY (phone, id)
);
我使用 datastax java 驱动程序
这是我的用户对象创建:
User user = new User();
user.setId(UUIDs.timeBased().toString());
user.setEmail(null);
user.setName("test-user");
user.setPhone(Credential.MD5.digest("user-" + i));
我创建了其中的 10k - i 是用户数组中用户的索引。我不想使用批量插入,而是模拟插入多条记录的压力。这是我的代码:
Cluster cluster = Cluster.builder()
.addContactPoints(CASSANDRA_CLUSTER_ADDRESSES)
.build();
final Session session = cluster.connect(keyspaceName);
final ThreadPoolExecutor tpe = (ThreadPoolExecutor) Executors.newCachedThreadPool();
for (final User user : users) {
tpe.execute(new Runnable() {
@Override
public void run() {
PreparedStatement ps =
session.prepare("INSERT INTO user (id, phone, name, email) VALUES (?, ?, ?, ?)");
BoundStatement bs = new BoundStatement(ps);
bs.bind(
user.getId(),
user.getPhone(),
user.getName(),
user.getEmail(),
);
session.executeAsync(bs);
}
});
}
tpe.shutdown();
tpe.awaitTermination...
- 计算记录数时(使用 cqlsh)我永远不会超过 4k(10k 中)
- 只有一个服务器正在执行写入(使用 opscenter 写入请求/所有节点图) - 我看不出原因:据我所知,密钥足够随机......
有人可以指出我的任何地方吗?