Search in sources :

Example 1 with CostDataStatistics

use of com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics in project GraphScope by alibaba.

the class TreeManager method optimizeCostModel.

public CostModelManager optimizeCostModel() {
    List<TreeNode> treeNodeList = TreeNodeUtils.buildTreeNodeListFromLeaf(this.getTreeLeaf());
    CostGraph costGraph = CostUtils.buildCostGraph(this.getTreeLeaf(), this.labelManager);
    NodeLabelManager nodeLabelManager = new NodeLabelManager();
    NodeLabelList previousNodeLabel = null;
    for (TreeNode treeNode : treeNodeList) {
        NodeLabelList nodeLabelList = NodeLabelList.buildNodeLabel(previousNodeLabel, treeNode, schema);
        nodeLabelManager.addNodeLabelList(nodeLabelList);
        previousNodeLabel = nodeLabelList;
    }
    int pathIndex = this.getQueryConfig().getInt(CompilerConstant.QUERY_COSTMODEL_PLAN_PATH, -1);
    List<CostPath> costPathList = costGraph.getCostPathList();
    CostPath useCostPath;
    if (pathIndex < 0 || pathIndex >= costPathList.size()) {
        CostDataStatistics costDataStatistics = CostDataStatistics.getInstance();
        List<Double> stepCountList = costDataStatistics.computeStepCountList(nodeLabelManager, treeNodeList);
        List<Double> shuffleThresholdList = Lists.newArrayList(1.0);
        for (int i = 1; i < stepCountList.size(); i++) {
            shuffleThresholdList.add(1.5);
        }
        useCostPath = costGraph.computePath(stepCountList, shuffleThresholdList);
    } else {
        useCostPath = costPathList.get(pathIndex);
        logger.info("Use specify cost path " + useCostPath.toString());
    }
    return new CostModelManager(costGraph, useCostPath);
}
Also used : NodeLabelManager(com.alibaba.maxgraph.compiler.cost.statistics.NodeLabelManager) SourceTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode) SourceVertexTreeNode(com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode) CostDataStatistics(com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics) NodeLabelList(com.alibaba.maxgraph.compiler.cost.statistics.NodeLabelList) CostModelManager(com.alibaba.maxgraph.compiler.cost.CostModelManager) CostGraph(com.alibaba.maxgraph.compiler.cost.CostGraph) CostPath(com.alibaba.maxgraph.compiler.cost.CostPath)

Example 2 with CostDataStatistics

use of com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics in project GraphScope by alibaba.

the class MixedOpProcessor method doProcessGraphTraversal.

private Long doProcessGraphTraversal(String script, Context context, Object traversal, long timeout, String queryId, Stopwatch timer) throws Exception {
    Long totalResultNum = 0L;
    Pair<GraphSchema, Long> snapshotSchema;
    GraphSchema schema;
    if (traversal instanceof GraphTraversal || traversal instanceof DfsTraversal) {
        final int resultIterationBatchSize = (Integer) context.getRequestMessage().optionalArgs(Tokens.ARGS_BATCH_SIZE).orElse(this.resultIterationBatchSize);
        NettyVertexRpcProcessor nettyVertexRpcProcessor = new NettyVertexRpcProcessor(context, resultIterationBatchSize, false);
        AbstractResultProcessor nettyResultProcessor = new NettyResultProcessor(queryId, script, context, executeConfig.getBatchQuerySize(), resultIterationBatchSize, false);
        totalResultNum = processQueryTraversal(script, traversal, timeout, queryId, timer, this.remoteRpcConnector, nettyVertexRpcProcessor, nettyResultProcessor);
    } else {
        snapshotSchema = this.schemaFetcher.getSchemaSnapshotPair();
        schema = snapshotSchema.getLeft();
        if (traversal instanceof PreparedTraversal) {
            throw new UnsupportedOperationException();
        } else if (traversal instanceof PreparedExecuteParam) {
            throw new UnsupportedOperationException();
        } else if (traversal instanceof ShowProcessListQuery) {
            TimelyResultProcessor nettyResultProcessor = newNettyResultProcessor(queryId, script, context, graph, schema);
            timelyExecutor.showProcessList(nettyResultProcessor);
        } else if (traversal instanceof CancelDataflow) {
            NettyResultProcessor nettyResultProcessor = newNettyResultProcessor(queryId, script, context, graph, schema);
            timelyExecutor.cancelDataflow(nettyResultProcessor, ((CancelDataflow) traversal).queryId);
        } else if (traversal instanceof RecordManager) {
            Object result = processRecordManager(RecordManager.class.cast(traversal));
            writeResultList(context, Lists.newArrayList(result), ResponseStatusCode.SUCCESS);
        } else if (traversal instanceof EstimateRequest) {
            writeResultList(context, Lists.newArrayList(processEstimateManager((EstimateRequest) traversal, timeout)), ResponseStatusCode.SUCCESS);
        } else if (traversal instanceof StatisticsRequest) {
            CostDataStatistics costDataStatistics = CostDataStatistics.getInstance();
            writeResultList(context, Lists.newArrayList(costDataStatistics.formatJson()), ResponseStatusCode.SUCCESS);
        } else if (traversal instanceof ShowPlanPathListRequest) {
            ShowPlanPathListRequest showPlanPathListRequest = (ShowPlanPathListRequest) traversal;
            writeResultList(context, Lists.newArrayList(buildCostPathList(showPlanPathListRequest.getTraversal())), ResponseStatusCode.SUCCESS);
        } else if (traversal instanceof Element) {
            writeResultList(context, Lists.newArrayList((Element) traversal), ResponseStatusCode.SUCCESS);
        } else if (traversal instanceof List) {
            writeResultList(context, (List) traversal, ResponseStatusCode.SUCCESS);
        } else if (traversal instanceof GraphSchema) {
            writeResultList(context, Lists.newArrayList(((GraphSchema) traversal).formatJson()), ResponseStatusCode.SUCCESS);
        } else if (traversal instanceof String) {
            writeResultList(context, Lists.newArrayList(traversal), ResponseStatusCode.SUCCESS);
        } else if (traversal != null && (!(traversal instanceof String) || !StringUtils.isEmpty(traversal.toString()))) {
            throw new IllegalArgumentException(traversal.toString());
        }
    }
    return totalResultNum;
}
Also used : PreparedTraversal(com.alibaba.maxgraph.compiler.prepare.PreparedTraversal) CancelDataflow(com.alibaba.maxgraph.sdkcommon.graph.CancelDataflow) Element(org.apache.tinkerpop.gremlin.structure.Element) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) DfsTraversal(com.alibaba.maxgraph.compiler.dfs.DfsTraversal) TimelyResultProcessor(com.alibaba.maxgraph.rpc.TimelyResultProcessor) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) CostDataStatistics(com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) ShowProcessListQuery(com.alibaba.maxgraph.sdkcommon.graph.ShowProcessListQuery) List(java.util.List) ShowPlanPathListRequest(com.alibaba.maxgraph.sdkcommon.graph.ShowPlanPathListRequest) EstimateRequest(com.alibaba.maxgraph.sdkcommon.graph.EstimateRequest) StatisticsRequest(com.alibaba.maxgraph.sdkcommon.graph.StatisticsRequest) RecordManager(com.alibaba.maxgraph.structure.manager.record.RecordManager) PreparedExecuteParam(com.alibaba.maxgraph.compiler.prepare.PreparedExecuteParam)

Example 3 with CostDataStatistics

use of com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics in project GraphScope by alibaba.

the class MixedOpProcessor method processEstimateManager.

private Object processEstimateManager(EstimateRequest request, long timeout) throws RetryGremlinException {
    Stopwatch timer = Stopwatch.createStarted();
    CostDataStatistics statistics = CostDataStatistics.getInstance();
    TinkerMaxGraph emptyGraph = new TinkerMaxGraph(null, null, null);
    MaxGraphTraversalSource g = (MaxGraphTraversalSource) emptyGraph.traversal();
    GraphSchema graphSchema = schemaFetcher.getSchemaSnapshotPair().getLeft();
    Map<String, Double> vertexCountList = Maps.newHashMap();
    for (GraphElement vertex : graphSchema.getVertexList()) {
        String queryId = String.valueOf(ThreadLocalRandom.current().nextLong());
        GraphTraversal vertexQuery = g.estimateVCount(vertex.getLabel());
        RemoteRpcProcessor remoteRpcProcessor = new DefaultVertexRpcProcessor();
        MemoryResultProcessor resultProcessor = new MemoryResultProcessor(executeConfig.getBatchQuerySize(), resultIterationBatchSize, queryId);
        processQueryTraversal(vertexQuery.toString(), vertexQuery, timeout, queryId, timer, this.httpRpcConnector, remoteRpcProcessor, resultProcessor);
        double countValue = Double.parseDouble(resultProcessor.getResultList().get(0).toString());
        vertexCountList.put(vertex.getLabel(), countValue);
    }
    Map<String, Double> edgeCountList = Maps.newHashMap();
    for (GraphElement edge : graphSchema.getEdgeList()) {
        GraphTraversal edgeQuery = g.estimateECount(edge.getLabel());
        String queryId = String.valueOf(ThreadLocalRandom.current().nextLong());
        RemoteRpcProcessor remoteRpcProcessor = new DefaultVertexRpcProcessor();
        MemoryResultProcessor resultProcessor = new MemoryResultProcessor(executeConfig.getBatchQuerySize(), resultIterationBatchSize, queryId);
        processQueryTraversal(edgeQuery.toString(), edgeQuery, timeout, queryId, timer, this.httpRpcConnector, remoteRpcProcessor, resultProcessor);
        double countValue = Double.parseDouble(resultProcessor.getResultList().get(0).toString());
        edgeCountList.put(edge.getLabel(), countValue);
    }
    for (Map.Entry<String, Double> entry : vertexCountList.entrySet()) {
        statistics.addVertexCount(entry.getKey(), entry.getValue());
    }
    for (Map.Entry<String, Double> entry : edgeCountList.entrySet()) {
        statistics.addEdgeCount(entry.getKey(), entry.getValue());
    }
    return "Estimate vertex/edge count success";
}
Also used : Stopwatch(com.google.common.base.Stopwatch) MaxGraphTraversalSource(com.alibaba.maxgraph.tinkerpop.traversal.MaxGraphTraversalSource) GraphSchema(com.alibaba.maxgraph.compiler.api.schema.GraphSchema) TinkerMaxGraph(com.alibaba.maxgraph.structure.graph.TinkerMaxGraph) CostDataStatistics(com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) GraphElement(com.alibaba.maxgraph.compiler.api.schema.GraphElement) Map(java.util.Map)

Aggregations

CostDataStatistics (com.alibaba.maxgraph.compiler.cost.statistics.CostDataStatistics)3 GraphElement (com.alibaba.maxgraph.compiler.api.schema.GraphElement)2 GraphSchema (com.alibaba.maxgraph.compiler.api.schema.GraphSchema)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 CostGraph (com.alibaba.maxgraph.compiler.cost.CostGraph)1 CostModelManager (com.alibaba.maxgraph.compiler.cost.CostModelManager)1 CostPath (com.alibaba.maxgraph.compiler.cost.CostPath)1 NodeLabelList (com.alibaba.maxgraph.compiler.cost.statistics.NodeLabelList)1 NodeLabelManager (com.alibaba.maxgraph.compiler.cost.statistics.NodeLabelManager)1 DfsTraversal (com.alibaba.maxgraph.compiler.dfs.DfsTraversal)1 PreparedExecuteParam (com.alibaba.maxgraph.compiler.prepare.PreparedExecuteParam)1 PreparedTraversal (com.alibaba.maxgraph.compiler.prepare.PreparedTraversal)1 SourceTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceTreeNode)1 SourceVertexTreeNode (com.alibaba.maxgraph.compiler.tree.source.SourceVertexTreeNode)1 TimelyResultProcessor (com.alibaba.maxgraph.rpc.TimelyResultProcessor)1 CancelDataflow (com.alibaba.maxgraph.sdkcommon.graph.CancelDataflow)1 EstimateRequest (com.alibaba.maxgraph.sdkcommon.graph.EstimateRequest)1 ShowPlanPathListRequest (com.alibaba.maxgraph.sdkcommon.graph.ShowPlanPathListRequest)1 ShowProcessListQuery (com.alibaba.maxgraph.sdkcommon.graph.ShowProcessListQuery)1 StatisticsRequest (com.alibaba.maxgraph.sdkcommon.graph.StatisticsRequest)1