{
final Random rnd = new Random(System.currentTimeMillis());
final CommandFactory commandFactory = CommandBenchmarkDispatcher.getCommandFactory(benchmarkParams.getCommand());
final SpeedLimit speedLimit = SpeedLimit.SpeedLimitHelper.getSpeedLimit(benchmarkParams.getOpsPerSec());
final PatternFacade facade = PatternFacade.DefaultFacade.getInstance();
final int workerID = workerIDs.get(CacheFactory.getCluster().getLocalMember().getId());
ExecutorService service = Executors.newFixedThreadPool(benchmarkParams.getThreadCount());
final CyclicBarrier startBarrier = new CyclicBarrier(benchmarkParams.getThreadCount());
final CountDownLatch finishLatch = new CountDownLatch(benchmarkParams.getThreadCount());
for(int t = 0; t != benchmarkParams.getThreadCount(); ++t)
{
final int threadNumber = t;
Callable<Void> worker = new Callable<Void>()
{
@Override
public Void call() throws Exception
{
try
{
startBarrier.await();
long commandsPerWorker = CommandBenchmarkDispatcher.getCommandsPerWorker(benchmarkParams);
long commandsPerWorkerThread = CommandBenchmarkDispatcher.getCommandsPerWorkerThead(benchmarkParams);
long offset = workerID * commandsPerWorker + threadNumber * commandsPerWorkerThread;
for(int c = 0; c != benchmarkParams.getCommandPerThread(); ++c)
{
Identifier ctx = contexts[rnd.nextInt(contexts.length)];
long id = offset + c * commandFactory.getMarksPerCommand();
speedLimit.accure();
facade.submit(ctx, commandFactory.createCommand(id, benchmarkParams.getReportBuffer()).send());
}
finishLatch.countDown();