Search in sources :

Example 1 with BlockMasterClient

use of alluxio.worker.block.BlockMasterClient in project alluxio by Alluxio.

the class RegisterWorkerBench method prepare.

@Override
public void prepare() throws Exception {
    // The task ID is different for local and cluster executions
    // So including that in the log can help associate the log to the run
    LOG.info("Task ID is {}", mBaseParameters.mId);
    mTierAliases = getTierAliases(mParameters.mTiers);
    mCapacityMap = Maps.toMap(mTierAliases, (tier) -> CAPACITY);
    mUsedMap = Maps.toMap(mTierAliases, (tier) -> 0L);
    // Generate block IDs heuristically
    Map<BlockStoreLocation, List<Long>> blockMap = RpcBenchPreparationUtils.generateBlockIdOnTiers(mParameters.mTiers);
    BlockMasterClient client = new BlockMasterClient(MasterClientContext.newBuilder(ClientContext.create(mConf)).build());
    mLocationBlockIdList = client.convertBlockListMapToProto(blockMap);
    // done once, so skip preparation when running in job worker
    if (!mBaseParameters.mDistributed) {
        // Prepare these block IDs concurrently
        LOG.info("Preparing blocks at the master");
        RpcBenchPreparationUtils.prepareBlocksInMaster(blockMap);
        LOG.info("Created all blocks at the master");
    }
    // Prepare worker IDs
    int numWorkers = mParameters.mConcurrency;
    mWorkerPool = RpcBenchPreparationUtils.prepareWorkerIds(client, numWorkers);
    Preconditions.checkState(mWorkerPool.size() == numWorkers, "Expecting %s workers but registered %s", numWorkers, mWorkerPool.size());
    LOG.info("Prepared worker IDs: {}", mWorkerPool);
}
Also used : RpcTaskResult(alluxio.stress.rpc.RpcTaskResult) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) EMPTY_CONFIG(alluxio.stress.cli.RpcBenchPreparationUtils.EMPTY_CONFIG) BlockMasterClient(alluxio.worker.block.BlockMasterClient) LoggerFactory(org.slf4j.LoggerFactory) CachingBlockMasterClient(alluxio.stress.CachingBlockMasterClient) BlockMasterBenchParameters(alluxio.stress.rpc.BlockMasterBenchParameters) Deque(java.util.Deque) PropertyKey(alluxio.conf.PropertyKey) BlockMasterSync(alluxio.worker.block.BlockMasterSync) ParametersDelegate(com.beust.jcommander.ParametersDelegate) ImmutableList(com.google.common.collect.ImmutableList) Duration(java.time.Duration) Map(java.util.Map) CAPACITY(alluxio.stress.cli.RpcBenchPreparationUtils.CAPACITY) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) ClientContext(alluxio.ClientContext) TierAlias(alluxio.stress.rpc.TierAlias) Logger(org.slf4j.Logger) LOST_STORAGE(alluxio.stress.cli.RpcBenchPreparationUtils.LOST_STORAGE) ImmutableMap(com.google.common.collect.ImmutableMap) Instant(java.time.Instant) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) List(java.util.List) MasterClientContext(alluxio.master.MasterClientContext) Preconditions(com.google.common.base.Preconditions) ArrayDeque(java.util.ArrayDeque) InstancedConfiguration(alluxio.conf.InstancedConfiguration) BlockMasterClient(alluxio.worker.block.BlockMasterClient) CachingBlockMasterClient(alluxio.stress.CachingBlockMasterClient) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation)

Example 2 with BlockMasterClient

use of alluxio.worker.block.BlockMasterClient in project alluxio by Alluxio.

the class WorkerHeartbeatBench method prepare.

@Override
public void prepare() throws Exception {
    // The task ID is different for local and cluster executions
    // So including that in the log can help associate the log to the run
    LOG.info("Task ID is {}", mBaseParameters.mId);
    // Prepare block IDs to use for this test
    // We prepare the IDs before test starts so each RPC does not waste time in the conversion
    Map<BlockStoreLocation, List<Long>> blockMap = RpcBenchPreparationUtils.generateBlockIdOnTiers(mParameters.mTiers);
    BlockMasterClient client = new BlockMasterClient(MasterClientContext.newBuilder(ClientContext.create(mConf)).build());
    mLocationBlockIdList = client.convertBlockListMapToProto(blockMap);
    // done once, so skip preparation when running in job worker
    if (!mBaseParameters.mDistributed) {
        // Prepare these block IDs concurrently
        LOG.info("Preparing block IDs at the master");
        RpcBenchPreparationUtils.prepareBlocksInMaster(blockMap);
        LOG.info("Created all blocks at the master");
    }
    // Prepare simulated workers
    int numWorkers = mParameters.mConcurrency;
    LOG.info("Register {} simulated workers for the test", numWorkers);
    mWorkerPool = RpcBenchPreparationUtils.prepareWorkerIds(client, numWorkers);
    Preconditions.checkState(mWorkerPool.size() == numWorkers, "Expecting %s workers but registered %s", numWorkers, mWorkerPool.size());
    RpcBenchPreparationUtils.registerWorkers(client, mWorkerPool);
    LOG.info("All workers registered with the master {}", mWorkerPool);
}
Also used : BlockMasterClient(alluxio.worker.block.BlockMasterClient) CachingBlockMasterClient(alluxio.stress.CachingBlockMasterClient) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation)

Example 3 with BlockMasterClient

use of alluxio.worker.block.BlockMasterClient in project alluxio by Alluxio.

the class BlockWorkerDataReaderTest method before.

@Before
public void before() throws Exception {
    BlockMasterClient blockMasterClient = mock(BlockMasterClient.class);
    BlockMasterClientPool blockMasterClientPool = spy(new BlockMasterClientPool());
    when(blockMasterClientPool.createNewResource()).thenReturn(blockMasterClient);
    TieredBlockStore blockStore = new TieredBlockStore();
    FileSystemMasterClient fileSystemMasterClient = mock(FileSystemMasterClient.class);
    Sessions sessions = mock(Sessions.class);
    // Connect to the real UFS for UFS read testing
    UfsManager ufsManager = mock(UfsManager.class);
    mRootUfs = ServerConfiguration.getString(PropertyKey.MASTER_MOUNT_TABLE_ROOT_UFS);
    UfsManager.UfsClient ufsClient = new UfsManager.UfsClient(() -> UnderFileSystem.Factory.create(mRootUfs, UnderFileSystemConfiguration.defaults(ServerConfiguration.global())), new AlluxioURI(mRootUfs));
    when(ufsManager.get(anyLong())).thenReturn(ufsClient);
    mBlockWorker = new DefaultBlockWorker(blockMasterClientPool, fileSystemMasterClient, sessions, blockStore, ufsManager);
    URIStatus dummyStatus = new URIStatus(new FileInfo().setBlockIds(Collections.singletonList(BLOCK_ID)));
    InStreamOptions options = new InStreamOptions(dummyStatus, FileSystemOptions.openFileDefaults(mConf), mConf);
    mDataReaderFactory = new BlockWorkerDataReader.Factory(mBlockWorker, BLOCK_ID, CHUNK_SIZE, options);
}
Also used : BlockMasterClientPool(alluxio.worker.block.BlockMasterClientPool) UfsManager(alluxio.underfs.UfsManager) Sessions(alluxio.Sessions) URIStatus(alluxio.client.file.URIStatus) TieredBlockStore(alluxio.worker.block.TieredBlockStore) InStreamOptions(alluxio.client.file.options.InStreamOptions) BlockWorkerDataReader(alluxio.client.block.stream.BlockWorkerDataReader) FileSystemMasterClient(alluxio.worker.file.FileSystemMasterClient) FileInfo(alluxio.wire.FileInfo) BlockMasterClient(alluxio.worker.block.BlockMasterClient) DefaultBlockWorker(alluxio.worker.block.DefaultBlockWorker) AlluxioURI(alluxio.AlluxioURI) Before(org.junit.Before)

Example 4 with BlockMasterClient

use of alluxio.worker.block.BlockMasterClient in project alluxio by Alluxio.

the class StreamRegisterWorkerBench method prepare.

@Override
public void prepare() throws Exception {
    // The task ID is different for local and cluster executions
    // So including that in the log can help associate the log to the run
    LOG.info("Task ID is {}", mBaseParameters.mId);
    mTierAliases = getTierAliases(mParameters.mTiers);
    mCapacityMap = Maps.toMap(mTierAliases, (tier) -> CAPACITY);
    mUsedMap = Maps.toMap(mTierAliases, (tier) -> 0L);
    // Generate block IDs heuristically
    Map<BlockStoreLocation, List<Long>> blockMap = RpcBenchPreparationUtils.generateBlockIdOnTiers(mParameters.mTiers);
    BlockMasterClient client = new BlockMasterClient(MasterClientContext.newBuilder(ClientContext.create(mConf)).build());
    mBlockMap = blockMap;
    // done once, so skip preparation when running in job worker
    if (!mBaseParameters.mDistributed) {
        // Prepare these block IDs concurrently
        LOG.info("Preparing blocks at the master");
        RpcBenchPreparationUtils.prepareBlocksInMaster(blockMap);
        LOG.info("Created all blocks at the master");
    }
    // Prepare worker IDs
    int numWorkers = mParameters.mConcurrency;
    mWorkerPool = RpcBenchPreparationUtils.prepareWorkerIds(client, numWorkers);
    Preconditions.checkState(mWorkerPool.size() == numWorkers, "Expecting %s workers but registered %s", numWorkers, mWorkerPool.size());
    LOG.info("Prepared worker IDs: {}", mWorkerPool);
}
Also used : RpcTaskResult(alluxio.stress.rpc.RpcTaskResult) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation) EMPTY_CONFIG(alluxio.stress.cli.RpcBenchPreparationUtils.EMPTY_CONFIG) BlockMasterClient(alluxio.worker.block.BlockMasterClient) LoggerFactory(org.slf4j.LoggerFactory) CachingBlockMasterClient(alluxio.stress.CachingBlockMasterClient) BlockMasterBenchParameters(alluxio.stress.rpc.BlockMasterBenchParameters) Deque(java.util.Deque) PropertyKey(alluxio.conf.PropertyKey) BlockMasterSync(alluxio.worker.block.BlockMasterSync) ParametersDelegate(com.beust.jcommander.ParametersDelegate) ImmutableList(com.google.common.collect.ImmutableList) Duration(java.time.Duration) Map(java.util.Map) CAPACITY(alluxio.stress.cli.RpcBenchPreparationUtils.CAPACITY) LocationBlockIdListEntry(alluxio.grpc.LocationBlockIdListEntry) ClientContext(alluxio.ClientContext) TierAlias(alluxio.stress.rpc.TierAlias) Logger(org.slf4j.Logger) LOST_STORAGE(alluxio.stress.cli.RpcBenchPreparationUtils.LOST_STORAGE) Instant(java.time.Instant) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) List(java.util.List) MasterClientContext(alluxio.master.MasterClientContext) Preconditions(com.google.common.base.Preconditions) ArrayDeque(java.util.ArrayDeque) InstancedConfiguration(alluxio.conf.InstancedConfiguration) BlockMasterClient(alluxio.worker.block.BlockMasterClient) CachingBlockMasterClient(alluxio.stress.CachingBlockMasterClient) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation)

Example 5 with BlockMasterClient

use of alluxio.worker.block.BlockMasterClient in project alluxio by Alluxio.

the class RpcBenchPreparationUtils method prepareBlocksInMaster.

/**
 * Prepare all relevant block IDs on the master side concurrently.
 *
 * @param locToBlocks a map from block location to block IDs
 */
public static void prepareBlocksInMaster(Map<BlockStoreLocation, List<Long>> locToBlocks) throws InterruptedException {
    // Since the task is I/O bound, set concurrency set to 4x CPUs
    int concurrency = Runtime.getRuntime().availableProcessors() * 4;
    // Partition the wanted block IDs to smaller jobs in order to utilize concurrency
    List<List<Long>> jobs = new ArrayList<>();
    long totalBlocks = 0;
    for (Map.Entry<BlockStoreLocation, List<Long>> e : locToBlocks.entrySet()) {
        List<Long> v = e.getValue();
        totalBlocks += v.size();
        jobs.addAll(Lists.partition(v, Math.min(v.size() / concurrency, 1_000)));
    }
    final long totalBlocksFinal = totalBlocks;
    LOG.info("Split block ID generation into {} jobs", jobs.size());
    for (List<Long> job : jobs) {
        LOG.debug("Block ids: [{},{}]", job.get(0), job.get(job.size() - 1));
    }
    ExecutorService pool = ExecutorServiceFactories.fixedThreadPool("rpc-bench-prepare", concurrency).create();
    long blockSize = sConf.getBytes(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT);
    CompletableFuture[] futures = new CompletableFuture[jobs.size()];
    AtomicInteger progress = new AtomicInteger(0);
    for (int i = 0; i < jobs.size(); i++) {
        List<Long> job = jobs.get(i);
        final int batchIndex = i;
        final int batchSize = job.size();
        CompletableFuture<Void> future = CompletableFuture.supplyAsync((Supplier<Void>) () -> {
            BlockMasterClient client = new BlockMasterClient(MasterClientContext.newBuilder(ClientContext.create(sConf)).build());
            for (Long blockId : job) {
                try {
                    client.commitBlockInUfs(blockId, blockSize);
                } catch (IOException e) {
                    LOG.error("Failed to commitBlockInUfs in batch {}, blockId={} total={}", batchIndex, blockId, totalBlocksFinal, e);
                }
            }
            long finishedCount = progress.addAndGet(batchSize);
            LOG.info("Generated {}th batch of {} blocks, {}% completed", batchIndex, batchSize, String.format("%.2f", 100.0 * finishedCount / totalBlocksFinal));
            return null;
        }, pool);
        futures[i] = (future);
    }
    LOG.info("Collect all results");
    try {
        CompletableFuture.allOf(futures).join();
    } finally {
        pool.shutdownNow();
        pool.awaitTermination(30, TimeUnit.SECONDS);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BlockMasterClient(alluxio.worker.block.BlockMasterClient) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) BlockStoreLocation(alluxio.worker.block.BlockStoreLocation)

Aggregations

BlockMasterClient (alluxio.worker.block.BlockMasterClient)5 BlockStoreLocation (alluxio.worker.block.BlockStoreLocation)4 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 CachingBlockMasterClient (alluxio.stress.CachingBlockMasterClient)3 Map (java.util.Map)3 ClientContext (alluxio.ClientContext)2 InstancedConfiguration (alluxio.conf.InstancedConfiguration)2 PropertyKey (alluxio.conf.PropertyKey)2 LocationBlockIdListEntry (alluxio.grpc.LocationBlockIdListEntry)2 MasterClientContext (alluxio.master.MasterClientContext)2 CAPACITY (alluxio.stress.cli.RpcBenchPreparationUtils.CAPACITY)2 EMPTY_CONFIG (alluxio.stress.cli.RpcBenchPreparationUtils.EMPTY_CONFIG)2 LOST_STORAGE (alluxio.stress.cli.RpcBenchPreparationUtils.LOST_STORAGE)2 BlockMasterBenchParameters (alluxio.stress.rpc.BlockMasterBenchParameters)2 RpcTaskResult (alluxio.stress.rpc.RpcTaskResult)2 TierAlias (alluxio.stress.rpc.TierAlias)2 BlockMasterSync (alluxio.worker.block.BlockMasterSync)2 ParametersDelegate (com.beust.jcommander.ParametersDelegate)2 Preconditions (com.google.common.base.Preconditions)2