Search in sources :

Example 21 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class AlgorithmTestBase method runAlgorithm.

public static void runAlgorithm(String algorithmParams, String... options) throws InterruptedException {
    final Logger log = Log.logger(AlgorithmTestBase.class);
    ExecutorService pool = Executors.newFixedThreadPool(2);
    CountDownLatch countDownLatch = new CountDownLatch(2);
    Throwable[] exceptions = new Throwable[2];
    pool.submit(() -> {
        WorkerService workerService = null;
        try {
            Map<String, String> params = new HashMap<>();
            params.put(RpcOptions.RPC_REMOTE_URL.name(), "127.0.0.1:8090");
            params.put(ComputerOptions.JOB_ID.name(), "algo_test_job1");
            params.put(ComputerOptions.JOB_WORKERS_COUNT.name(), "1");
            params.put(ComputerOptions.TRANSPORT_SERVER_PORT.name(), "8086");
            params.put(ComputerOptions.BSP_REGISTER_TIMEOUT.name(), "100000");
            params.put(ComputerOptions.BSP_LOG_INTERVAL.name(), "30000");
            params.put(ComputerOptions.BSP_MAX_SUPER_STEP.name(), "10");
            params.put(ComputerOptions.ALGORITHM_PARAMS_CLASS.name(), algorithmParams);
            if (options != null) {
                for (int i = 0; i < options.length; i += 2) {
                    params.put(options[i], options[i + 1]);
                }
            }
            Config config = ComputerContextUtil.initContext(params);
            workerService = new MockWorkerService();
            workerService.init(config);
            workerService.execute();
        } catch (Throwable e) {
            LOG.error("Failed to start worker", e);
            exceptions[0] = e;
            // If worker failed, the master also should quit
            while (countDownLatch.getCount() > 0) {
                countDownLatch.countDown();
            }
        } finally {
            if (workerService != null) {
                workerService.close();
            }
            countDownLatch.countDown();
        }
    });
    pool.submit(() -> {
        MasterService masterService = null;
        try {
            Map<String, String> params = new HashMap<>();
            params.put(RpcOptions.RPC_SERVER_HOST.name(), "localhost");
            params.put(RpcOptions.RPC_SERVER_PORT.name(), "8090");
            params.put(ComputerOptions.JOB_ID.name(), "algo_test_job1");
            params.put(ComputerOptions.JOB_WORKERS_COUNT.name(), "1");
            params.put(ComputerOptions.BSP_REGISTER_TIMEOUT.name(), "100000");
            params.put(ComputerOptions.BSP_LOG_INTERVAL.name(), "30000");
            params.put(ComputerOptions.BSP_MAX_SUPER_STEP.name(), "10");
            params.put(ComputerOptions.ALGORITHM_PARAMS_CLASS.name(), algorithmParams);
            if (options != null) {
                for (int i = 0; i < options.length; i += 2) {
                    params.put(options[i], options[i + 1]);
                }
            }
            Config config = ComputerContextUtil.initContext(params);
            masterService = new MasterService();
            masterService.init(config);
            masterService.execute();
        } catch (Throwable e) {
            LOG.error("Failed to start master", e);
            exceptions[1] = e;
            // If master failed, the worker also should quit
            while (countDownLatch.getCount() > 0) {
                countDownLatch.countDown();
            }
        } finally {
            /*
                 * It must close the service first. The pool will be shutdown
                 * if count down is executed first, and the server thread in
                 * master service will not be closed.
                 */
            if (masterService != null) {
                masterService.close();
            }
            countDownLatch.countDown();
        }
    });
    countDownLatch.await();
    pool.shutdownNow();
    Assert.assertFalse(Arrays.asList(exceptions).toString(), existError(exceptions));
}
Also used : HashMap(java.util.HashMap) Config(com.baidu.hugegraph.computer.core.config.Config) Logger(org.slf4j.Logger) CountDownLatch(java.util.concurrent.CountDownLatch) MasterService(com.baidu.hugegraph.computer.core.master.MasterService) MockWorkerService(com.baidu.hugegraph.computer.core.worker.MockWorkerService) WorkerService(com.baidu.hugegraph.computer.core.worker.WorkerService) MockWorkerService(com.baidu.hugegraph.computer.core.worker.MockWorkerService) ExecutorService(java.util.concurrent.ExecutorService)

Example 22 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class PointerCombinerTest method testVertexPropertiesCombiner.

@Test
public void testVertexPropertiesCombiner() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName(), ComputerOptions.WORKER_VERTEX_PROPERTIES_COMBINER_CLASS, MergeOldPropertiesCombiner.class.getName());
    Combiner<Properties> valueCombiner = config.createObject(ComputerOptions.WORKER_VERTEX_PROPERTIES_COMBINER_CLASS);
    GraphFactory graphFactory = graphFactory();
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(graphFactory::createProperties, valueCombiner);
    try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
        BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        Properties value1 = graphFactory.createProperties();
        value1.put("p1", new LongValue(1L));
        Properties value2 = graphFactory.createProperties();
        value2.put("p2", new LongValue(2L));
        value1.write(bytesOutput1);
        value2.write(bytesOutput2);
        Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
        Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
        Pointer pointer = combiner.combine(pointer1, pointer2);
        BytesInput input = IOFactory.createBytesInput(pointer.bytes());
        Properties combinedValue = graphFactory.createProperties();
        combinedValue.read(input);
        Map<String, Value> map = combinedValue.get();
        Assert.assertEquals(2, map.size());
        Assert.assertEquals(new LongValue(1L), map.get("p1"));
        Assert.assertEquals(new LongValue(2L), map.get("p2"));
    }
}
Also used : GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) BytesInput(com.baidu.hugegraph.computer.core.io.BytesInput) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) Value(com.baidu.hugegraph.computer.core.graph.value.Value) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Test(org.junit.Test)

Example 23 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class PointerCombinerTest method testCombineEdgePropertiesFail.

@Test
public void testCombineEdgePropertiesFail() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.WORKER_COMBINER_CLASS, DoubleValueSumCombiner.class.getName(), ComputerOptions.WORKER_EDGE_PROPERTIES_COMBINER_CLASS, MergeOldPropertiesCombiner.class.getName());
    Combiner<Properties> valueCombiner = config.createObject(ComputerOptions.WORKER_EDGE_PROPERTIES_COMBINER_CLASS);
    GraphFactory graphFactory = graphFactory();
    PointerCombiner combiner = SorterTestUtil.createPointerCombiner(graphFactory::createProperties, valueCombiner);
    try (BytesOutput bytesOutput1 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE);
        BytesOutput bytesOutput2 = IOFactory.createBytesOutput(Constants.SMALL_BUF_SIZE)) {
        Properties value1 = graphFactory.createProperties();
        value1.put("p1", new LongValue(1L));
        Properties value2 = graphFactory.createProperties();
        value2.put("p2", new LongValue(2L));
        // Only write count.
        bytesOutput1.writeInt(1);
        value2.write(bytesOutput2);
        Pointer pointer1 = new InlinePointer(bytesOutput1.buffer(), bytesOutput1.position());
        Pointer pointer2 = new InlinePointer(bytesOutput2.buffer(), bytesOutput2.position());
        Assert.assertThrows(ComputerException.class, () -> {
            combiner.combine(pointer1, pointer2);
        }, e -> {
            Assert.assertContains("Failed to combine pointer", e.getMessage());
        });
    }
}
Also used : GraphFactory(com.baidu.hugegraph.computer.core.graph.GraphFactory) BytesOutput(com.baidu.hugegraph.computer.core.io.BytesOutput) Config(com.baidu.hugegraph.computer.core.config.Config) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Pointer(com.baidu.hugegraph.computer.core.store.entry.Pointer) InlinePointer(com.baidu.hugegraph.computer.core.store.entry.InlinePointer) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) Test(org.junit.Test)

Example 24 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class EtcdBspTest method setup.

@Before
public void setup() {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_ID, "local_001", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.BSP_LOG_INTERVAL, "30000", ComputerOptions.BSP_MAX_SUPER_STEP, "2");
    this.bsp4Master = new Bsp4Master(config);
    this.bsp4Master.clean();
    this.masterInfo = new ContainerInfo(-1, "localhost", 8001, 8002);
    this.workerInfo = new ContainerInfo(0, "localhost", 8003, 8004);
    this.bsp4Worker = new Bsp4Worker(config, this.workerInfo);
    this.maxSuperStep = config.get(ComputerOptions.BSP_MAX_SUPER_STEP);
}
Also used : Config(com.baidu.hugegraph.computer.core.config.Config) ContainerInfo(com.baidu.hugegraph.computer.core.common.ContainerInfo) Before(org.junit.Before)

Example 25 with Config

use of com.baidu.hugegraph.computer.core.config.Config in project hugegraph-computer by hugegraph.

the class ComputeMessageRecvPartitionTest method testNotCombineMessageRecvPartition.

@Test
public void testNotCombineMessageRecvPartition() throws IOException {
    Config config = UnitTestBase.updateWithRequiredOptions(ComputerOptions.JOB_ID, "local_001", ComputerOptions.JOB_WORKERS_COUNT, "1", ComputerOptions.JOB_PARTITIONS_COUNT, "1", ComputerOptions.WORKER_COMBINER_CLASS, Null.class.getName(), ComputerOptions.WORKER_DATA_DIRS, "[data_dir1, data_dir2]", ComputerOptions.WORKER_RECEIVED_BUFFERS_BYTES_LIMIT, "10", ComputerOptions.ALGORITHM_MESSAGE_CLASS, IdList.class.getName(), ComputerOptions.TRANSPORT_RECV_FILE_MODE, "false");
    FileUtils.deleteQuietly(new File("data_dir1"));
    FileUtils.deleteQuietly(new File("data_dir2"));
    FileManager fileManager = new FileManager();
    fileManager.init(config);
    SortManager sortManager = new RecvSortManager(context());
    sortManager.init(config);
    SuperstepFileGenerator fileGenerator = new SuperstepFileGenerator(fileManager, 0);
    ComputeMessageRecvPartition partition = new ComputeMessageRecvPartition(context(), fileGenerator, sortManager);
    Assert.assertEquals("msg", partition.type());
    addTwentyDuplicateIdValueListMessageBuffer(partition::addBuffer);
    checkIdValueListMessages(partition.iterator());
    fileManager.close(config);
    sortManager.close(config);
}
Also used : Null(com.baidu.hugegraph.computer.core.config.Null) SuperstepFileGenerator(com.baidu.hugegraph.computer.core.store.SuperstepFileGenerator) Config(com.baidu.hugegraph.computer.core.config.Config) File(java.io.File) IdList(com.baidu.hugegraph.computer.core.graph.value.IdList) FileManager(com.baidu.hugegraph.computer.core.store.FileManager) RecvSortManager(com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager) SortManager(com.baidu.hugegraph.computer.core.sort.sorting.SortManager) RecvSortManager(com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager) Test(org.junit.Test)

Aggregations

Config (com.baidu.hugegraph.computer.core.config.Config)33 Test (org.junit.Test)25 BytesInput (com.baidu.hugegraph.computer.core.io.BytesInput)6 File (java.io.File)6 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)5 BytesOutput (com.baidu.hugegraph.computer.core.io.BytesOutput)5 IntValueSumCombiner (com.baidu.hugegraph.computer.core.combiner.IntValueSumCombiner)4 PointerCombiner (com.baidu.hugegraph.computer.core.combiner.PointerCombiner)4 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)4 MasterService (com.baidu.hugegraph.computer.core.master.MasterService)4 Sorter (com.baidu.hugegraph.computer.core.sort.Sorter)4 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)3 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)3 Id (com.baidu.hugegraph.computer.core.graph.id.Id)3 RandomAccessInput (com.baidu.hugegraph.computer.core.io.RandomAccessInput)3 CombineKvOuterSortFlusher (com.baidu.hugegraph.computer.core.sort.flusher.CombineKvOuterSortFlusher)3 RecvSortManager (com.baidu.hugegraph.computer.core.sort.sorting.RecvSortManager)3 SortManager (com.baidu.hugegraph.computer.core.sort.sorting.SortManager)3 InlinePointer (com.baidu.hugegraph.computer.core.store.entry.InlinePointer)3 Pointer (com.baidu.hugegraph.computer.core.store.entry.Pointer)3