use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project sofa-jraft by sofastack.
the class CounterClient method main.
public static void main(final String[] args) throws Exception {
if (args.length != 2) {
System.out.println("Usage : java com.alipay.sofa.jraft.example.counter.CounterClient {groupId} {conf}");
System.out.println("Example: java com.alipay.sofa.jraft.example.counter.CounterClient counter 127.0.0.1:8081,127.0.0.1:8082,127.0.0.1:8083");
System.exit(1);
}
final String groupId = args[0];
final String confStr = args[1];
CounterGrpcHelper.initGRpc();
final Configuration conf = new Configuration();
if (!conf.parse(confStr)) {
throw new IllegalArgumentException("Fail to parse conf:" + confStr);
}
RouteTable.getInstance().updateConfiguration(groupId, conf);
final CliClientServiceImpl cliClientService = new CliClientServiceImpl();
cliClientService.init(new CliOptions());
if (!RouteTable.getInstance().refreshLeader(cliClientService, groupId, 1000).isOk()) {
throw new IllegalStateException("Refresh leader failed");
}
final PeerId leader = RouteTable.getInstance().selectLeader(groupId);
System.out.println("Leader is " + leader);
final int n = 1000;
final CountDownLatch latch = new CountDownLatch(n);
final long start = System.currentTimeMillis();
for (int i = 0; i < n; i++) {
incrementAndGet(cliClientService, leader, i, latch);
}
latch.await();
System.out.println(n + " ops, cost : " + (System.currentTimeMillis() - start) + " ms.");
System.exit(0);
}
use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project jdchain-core by blockchain-jd-com.
the class ParticipantManagerService4Raft method shuffleInvoke.
private RpcResponse shuffleInvoke(ParticipantContext context, List<NodeSettings> origConsensusNodes, Object request) {
Collections.shuffle(origConsensusNodes);
for (NodeSettings nodeSettings : origConsensusNodes) {
RaftNodeSettings raftNodeSettings = (RaftNodeSettings) nodeSettings;
Endpoint remoteEndpoint = new Endpoint(raftNodeSettings.getNetworkAddress().getHost(), raftNodeSettings.getNetworkAddress().getPort());
CliClientServiceImpl cliClientService = createRpcClient(context);
if (cliClientService.connect(remoteEndpoint)) {
return invoke(context, remoteEndpoint, request);
}
}
return RpcResponse.fail(-1, "not found connected nodes");
}
use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project sofa-jraft by sofastack.
the class AtomicClientTest method main.
public static void main(String[] args) throws Exception {
final RouteTable table = RouteTable.getInstance();
table.updateConfiguration("atomic_0", JRaftUtils.getConfiguration("127.0.0.1:8609,127.0.0.1:8610,127.0.0.1:8611"));
final CliClientServiceImpl cliClientService = new CliClientServiceImpl();
cliClientService.init(new CliOptions());
final Status st = table.refreshLeader(cliClientService, "atomic_0", 10000);
System.out.println(st);
final AtomicClient cli = new AtomicClient("atomic", JRaftUtils.getConfiguration("localhost:8610"));
final PeerId leader = table.selectLeader("atomic_0");
cli.start();
final int threads = 30;
final int count = 10000;
final CyclicBarrier barrier = new CyclicBarrier(threads + 1);
for (int t = 0; t < threads; t++) {
new Thread() {
@Override
public void run() {
long sum = 0;
try {
barrier.await();
final PeerId peer = new PeerId("localhost", 8611);
for (int i = 0; i < count; i++) {
sum += cli.get(leader, "a", true, false);
// sum += cli.addAndGet(leader, "a", i);
}
barrier.await();
} catch (final Exception e) {
e.printStackTrace();
} finally {
System.out.println("sum=" + sum);
}
}
}.start();
}
final long start = System.currentTimeMillis();
barrier.await();
barrier.await();
final long cost = System.currentTimeMillis() - start;
final long tps = Math.round(threads * count * 1000.0 / cost);
System.out.println("tps=" + tps + ",cost=" + cost + " ms.");
cli.shutdown();
}
use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project sofa-jraft by sofastack.
the class RouteTableTest method setup.
@Before
public void setup() throws Exception {
cliClientService = new CliClientServiceImpl();
cliClientService.init(new CliOptions());
this.dataPath = TestUtils.mkTempDir();
FileUtils.forceMkdir(new File(this.dataPath));
assertEquals(NodeImpl.GLOBAL_NUM_NODES.get(), 0);
final List<PeerId> peers = TestUtils.generatePeers(3);
cluster = new TestCluster(groupId, dataPath, peers);
for (final PeerId peer : peers) {
cluster.start(peer.getEndpoint());
}
cluster.waitLeader();
}
use of com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl in project sofa-jraft by sofastack.
the class CliServiceImpl method init.
@Override
public synchronized boolean init(final CliOptions opts) {
Requires.requireNonNull(opts, "Null cli options");
if (this.cliClientService != null) {
return true;
}
this.cliOptions = opts;
this.cliClientService = new CliClientServiceImpl();
return this.cliClientService.init(this.cliOptions);
}
Aggregations