You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hugegraph.apache.org by GitBox <gi...@apache.org> on 2022/04/25 09:13:36 UTC

[GitHub] [incubator-hugegraph-computer] corgiboygsj commented on a diff in pull request #177: feature: support partition concurrent compute

corgiboygsj commented on code in PR #177:
URL: https://github.com/apache/incubator-hugegraph-computer/pull/177#discussion_r857418405


##########
computer-core/src/main/java/com/baidu/hugegraph/computer/core/sender/MessageSendPartition.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2017 HugeGraph Authors
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.baidu.hugegraph.computer.core.sender;
+
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.baidu.hugegraph.computer.core.common.ComputerContext;
+import com.baidu.hugegraph.computer.core.receiver.MessageStat;
+
+public class MessageSendPartition {
+
+    private final ComputerContext context;
+    private final int threshold;
+    private final int capacity;
+
+    private final Map<Thread, WriteBuffers> buffers;
+
+    public MessageSendPartition(ComputerContext context,
+                                int threshold, int capacity) {
+        this.context = context;
+        this.threshold = threshold;
+        this.capacity = capacity;
+
+        this.buffers = new ConcurrentHashMap<>();
+    }
+
+    public WriteBuffers get() {
+        Thread current = Thread.currentThread();
+        WriteBuffers buffer = this.buffers.get(current);
+        if (buffer == null) {
+            buffer = new WriteBuffers(this.context, this.threshold,
+                                      this.capacity);
+            this.buffers.put(current, buffer);
+        }
+        return buffer;
+    }
+
+    public void clear() {
+        this.buffers.clear();
+    }
+
+    public void resetMessageWritten() {
+        for (WriteBuffers buffer : this.buffers.values()) {
+            buffer.resetMessageWritten();
+        }
+    }
+
+    public MessageStat messageWritten() {

Review Comment:
   can do this, but they are only accessed by the main thread



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org