Search in sources :

Example 1 with RpcBenchParameters

use of alluxio.stress.rpc.RpcBenchParameters in project alluxio by Alluxio.

the class RpcBench method runLocal.

@Override
public RpcTaskResult runLocal() throws Exception {
    RpcBenchParameters rpcBenchParameters = getParameters();
    LOG.info("Running locally with {} threads", rpcBenchParameters.mConcurrency);
    List<CompletableFuture<RpcTaskResult>> futures = new ArrayList<>();
    try {
        for (int i = 0; i < rpcBenchParameters.mConcurrency; i++) {
            CompletableFuture<RpcTaskResult> future = CompletableFuture.supplyAsync(() -> {
                RpcTaskResult threadResult = new RpcTaskResult();
                threadResult.setBaseParameters(mBaseParameters);
                threadResult.setParameters(rpcBenchParameters);
                try {
                    RpcTaskResult r = runRPC();
                    threadResult.merge(r);
                    return threadResult;
                } catch (Exception e) {
                    LOG.error("Failed to execute RPC", e);
                    threadResult.addError(e.getMessage());
                    return threadResult;
                }
            }, getPool());
            futures.add(future);
        }
        LOG.info("{} jobs submitted", futures.size());
        // Collect the result
        RpcTaskResult merged = futures.stream().map(CompletableFuture::join).reduce(new RpcTaskResult(mBaseParameters, rpcBenchParameters), (sum, one) -> {
            sum.merge(one);
            return sum;
        });
        return merged;
    } catch (Exception e) {
        LOG.error("Failed to execute RPC in pool", e);
        RpcTaskResult result = new RpcTaskResult();
        result.setBaseParameters(mBaseParameters);
        result.setParameters(rpcBenchParameters);
        result.addError(e.getMessage());
        return result;
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) RpcTaskResult(alluxio.stress.rpc.RpcTaskResult) RpcBenchParameters(alluxio.stress.rpc.RpcBenchParameters)

Aggregations

RpcBenchParameters (alluxio.stress.rpc.RpcBenchParameters)1 RpcTaskResult (alluxio.stress.rpc.RpcTaskResult)1 ArrayList (java.util.ArrayList)1 CompletableFuture (java.util.concurrent.CompletableFuture)1