You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2020/11/24 23:15:03 UTC

[GitHub] [incubator-pinot] mayankshriv commented on a change in pull request #6287: Parallelize segment index init and building

mayankshriv commented on a change in pull request #6287:
URL: https://github.com/apache/incubator-pinot/pull/6287#discussion_r529956834



##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/creator/RecordReaderSegmentCreationDataSource.java
##########
@@ -53,26 +51,11 @@ public SegmentPreIndexStatsCollector gatherStats(StatsCollectorConfig statsColle
       SegmentPreIndexStatsCollector collector = new SegmentPreIndexStatsCollectorImpl(statsCollectorConfig);
       collector.init();
 
-      // Gather the stats
-      GenericRow reuse = new GenericRow();
-      while (_recordReader.hasNext()) {
-        reuse.clear();
+      ParallelRowProcessor prp = new ParallelRowProcessor(
+          _recordReader, 

Review comment:
       Use Pinot formatting.

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/BuildRingBufferConsumer.java
##########
@@ -0,0 +1,88 @@
+/**
+ * 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 org.apache.pinot.core.segment.creator.impl;
+
+import java.util.Collection;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import com.lmax.disruptor.EventHandler;
+import org.apache.pinot.core.data.recordtransformer.RecordTransformer;
+import org.apache.pinot.core.segment.creator.SegmentCreator;
+import org.apache.pinot.core.util.IngestionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BuildRingBufferConsumer implements EventHandler<GenericRow> {
+  private static final Logger LOGGER = LoggerFactory.getLogger(BuildRingBufferConsumer.class);
+  private RecordTransformer recordTransformer = null;
+  private SegmentCreator indexCreator = null;
+
+  private long totalRecordReadTime = 0;

Review comment:
       Please use Pinot code styling. We name all data members with `_` prefix and avoid `this.`.

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/InitRingBufferConsumer.java
##########
@@ -0,0 +1,62 @@
+/**
+ * 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 org.apache.pinot.core.segment.creator.impl;
+
+import java.util.Collection;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import com.lmax.disruptor.EventHandler;
+import org.apache.pinot.core.data.recordtransformer.RecordTransformer;
+import org.apache.pinot.core.segment.creator.SegmentPreIndexStatsCollector;
+import org.apache.pinot.core.util.IngestionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class InitRingBufferConsumer implements EventHandler<GenericRow> {

Review comment:
       Rename to `RingBufferConsumerInitializer` (`InitRingBufferConsumer` sounds more like a method name than a class name)?

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/creator/RecordReaderSegmentCreationDataSource.java
##########
@@ -53,26 +51,11 @@ public SegmentPreIndexStatsCollector gatherStats(StatsCollectorConfig statsColle
       SegmentPreIndexStatsCollector collector = new SegmentPreIndexStatsCollectorImpl(statsCollectorConfig);
       collector.init();
 
-      // Gather the stats
-      GenericRow reuse = new GenericRow();
-      while (_recordReader.hasNext()) {
-        reuse.clear();
+      ParallelRowProcessor prp = new ParallelRowProcessor(

Review comment:
       Name the variable `parallelRowProcessor` for readability?

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/BuildRingBufferConsumer.java
##########
@@ -0,0 +1,88 @@
+/**
+ * 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 org.apache.pinot.core.segment.creator.impl;
+
+import java.util.Collection;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import com.lmax.disruptor.EventHandler;
+import org.apache.pinot.core.data.recordtransformer.RecordTransformer;
+import org.apache.pinot.core.segment.creator.SegmentCreator;
+import org.apache.pinot.core.util.IngestionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BuildRingBufferConsumer implements EventHandler<GenericRow> {
+  private static final Logger LOGGER = LoggerFactory.getLogger(BuildRingBufferConsumer.class);
+  private RecordTransformer recordTransformer = null;
+  private SegmentCreator indexCreator = null;
+
+  private long totalRecordReadTime = 0;
+  private long totalIndexTime = 0;
+  private long totalStatsCollectorTime = 0;
+
+  public BuildRingBufferConsumer(RecordTransformer newTransformer, SegmentCreator newSegmentCreator) {

Review comment:
       Please add javadoc for public classes and methods. Also, the class name could be a bit more readable (something to do with segment generation?).

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/BuildRingBufferConsumer.java
##########
@@ -0,0 +1,88 @@
+/**
+ * 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 org.apache.pinot.core.segment.creator.impl;
+
+import java.util.Collection;
+import org.apache.pinot.spi.data.readers.GenericRow;
+import com.lmax.disruptor.EventHandler;
+import org.apache.pinot.core.data.recordtransformer.RecordTransformer;
+import org.apache.pinot.core.segment.creator.SegmentCreator;
+import org.apache.pinot.core.util.IngestionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BuildRingBufferConsumer implements EventHandler<GenericRow> {
+  private static final Logger LOGGER = LoggerFactory.getLogger(BuildRingBufferConsumer.class);
+  private RecordTransformer recordTransformer = null;
+  private SegmentCreator indexCreator = null;
+
+  private long totalRecordReadTime = 0;
+  private long totalIndexTime = 0;
+  private long totalStatsCollectorTime = 0;
+
+  public BuildRingBufferConsumer(RecordTransformer newTransformer, SegmentCreator newSegmentCreator) {
+    this.recordTransformer = newTransformer;
+    this.indexCreator = newSegmentCreator;
+  }
+
+  public void onEvent(GenericRow row, long sequence, boolean endOfBatch) {
+    try {
+      long recordReadStartTime = System.currentTimeMillis();

Review comment:
       Measuring processing time for each row seems like an overhead, we should avoid this.

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/ParallelRowProcessor.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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 org.apache.pinot.core.segment.creator.impl;
+
+import com.lmax.disruptor.dsl.Disruptor;
+import com.lmax.disruptor.EventHandler;
+import com.lmax.disruptor.dsl.ProducerType;
+import com.lmax.disruptor.BusySpinWaitStrategy;
+import com.lmax.disruptor.RingBuffer;
+import com.lmax.disruptor.util.DaemonThreadFactory;
+import org.apache.pinot.spi.data.readers.RecordReader;
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+public class ParallelRowProcessor {
+    /* bufferSize, Needs to fit L3 cache & must be power of 2 */
+    public static final int RING_SIZE = 64;
+    private RecordReader reader;
+    private Disruptor<GenericRow> disruptor;
+
+    public ParallelRowProcessor(RecordReader reader, EventHandler<GenericRow> handler) {
+        this.reader = reader;
+
+        this.disruptor = new Disruptor<GenericRow>(
+            GenericRow::new, 

Review comment:
       Will this create more garbage?

##########
File path: pinot-core/src/main/java/org/apache/pinot/core/segment/creator/impl/ParallelRowProcessor.java
##########
@@ -0,0 +1,68 @@
+/**
+ * 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 org.apache.pinot.core.segment.creator.impl;
+
+import com.lmax.disruptor.dsl.Disruptor;
+import com.lmax.disruptor.EventHandler;
+import com.lmax.disruptor.dsl.ProducerType;
+import com.lmax.disruptor.BusySpinWaitStrategy;
+import com.lmax.disruptor.RingBuffer;
+import com.lmax.disruptor.util.DaemonThreadFactory;
+import org.apache.pinot.spi.data.readers.RecordReader;
+import org.apache.pinot.spi.data.readers.GenericRow;
+
+public class ParallelRowProcessor {
+    /* bufferSize, Needs to fit L3 cache & must be power of 2 */
+    public static final int RING_SIZE = 64;
+    private RecordReader reader;
+    private Disruptor<GenericRow> disruptor;
+
+    public ParallelRowProcessor(RecordReader reader, EventHandler<GenericRow> handler) {
+        this.reader = reader;
+
+        this.disruptor = new Disruptor<GenericRow>(
+            GenericRow::new, 
+            RING_SIZE, 
+            DaemonThreadFactory.INSTANCE,
+            ProducerType.SINGLE,
+            new BusySpinWaitStrategy());
+
+        this.disruptor.handleEventsWith(handler);
+    }
+
+    public void Run() throws Exception {

Review comment:
       Method names should start with lower case.




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org