[NO ISSUE][OTR] Eliminate Per Tuple Object Creation
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- Replace unneeded LinkedList by ArrayList in
ChainedLSMDiskComponentBulkLoader and eliminate
iterator creation per tuple.
- Eliminate iterator creation per tuple in LSMHarness.
Change-Id: I7d3a5472c70c4564290daeb6e99d508000521119
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2587
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Michael Blow <mblow@apache.org>
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/ChainedLSMDiskComponentBulkLoader.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/ChainedLSMDiskComponentBulkLoader.java
index f38614c..abb0c76 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/ChainedLSMDiskComponentBulkLoader.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/ChainedLSMDiskComponentBulkLoader.java
@@ -18,20 +18,21 @@
*/
package org.apache.hyracks.storage.am.lsm.common.impls;
-import java.util.LinkedList;
+import java.util.ArrayList;
import java.util.List;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.dataflow.common.data.accessors.ITupleReference;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponentBulkLoader;
+import org.apache.hyracks.util.annotations.CriticalPath;
/**
* Class encapsulates a chain of operations, happening during an LSM disk component bulkload
*/
public class ChainedLSMDiskComponentBulkLoader implements ILSMDiskComponentBulkLoader {
- private List<IChainedComponentBulkLoader> bulkloaderChain = new LinkedList<>();
+ private List<IChainedComponentBulkLoader> bulkloaderChain = new ArrayList<>();
private boolean isEmptyComponent = true;
private boolean cleanedUpArtifacts = false;
private final ILSMDiskComponent diskComponent;
@@ -47,11 +48,13 @@
}
@Override
+ @CriticalPath
public void add(ITupleReference tuple) throws HyracksDataException {
try {
ITupleReference t = tuple;
- for (IChainedComponentBulkLoader lsmBulkloader : bulkloaderChain) {
- t = lsmBulkloader.add(t);
+ final int bulkloadersCount = bulkloaderChain.size();
+ for (int i = 0; i < bulkloadersCount; i++) {
+ t = bulkloaderChain.get(i).add(t);
}
} catch (Exception e) {
cleanupArtifacts();
@@ -63,11 +66,13 @@
}
@Override
+ @CriticalPath
public void delete(ITupleReference tuple) throws HyracksDataException {
try {
ITupleReference t = tuple;
- for (IChainedComponentBulkLoader lsmOperation : bulkloaderChain) {
- t = lsmOperation.delete(t);
+ final int bulkloadersCount = bulkloaderChain.size();
+ for (int i = 0; i < bulkloadersCount; i++) {
+ t = bulkloaderChain.get(i).delete(t);
}
} catch (Exception e) {
cleanupArtifacts();
diff --git a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
index 59f48d4..1dbaa3c 100644
--- a/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
+++ b/hyracks-fullstack/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/LSMHarness.java
@@ -54,6 +54,7 @@
import org.apache.hyracks.storage.am.lsm.common.util.IOOperationUtils;
import org.apache.hyracks.storage.common.IIndexCursor;
import org.apache.hyracks.storage.common.ISearchPredicate;
+import org.apache.hyracks.util.annotations.CriticalPath;
import org.apache.hyracks.util.trace.ITracer;
import org.apache.hyracks.util.trace.ITracer.Scope;
import org.apache.logging.log4j.Level;
@@ -180,6 +181,7 @@
}
}
+ @CriticalPath
protected boolean enterComponents(ILSMIndexOperationContext ctx, LSMOperationType opType)
throws HyracksDataException {
validateOperationEnterComponentsState(ctx);
@@ -187,9 +189,11 @@
int numEntered = 0;
boolean entranceSuccessful = false;
try {
- for (ILSMComponent c : components) {
- boolean isMutableComponent = numEntered == 0 && c.getType() == LSMComponentType.MEMORY ? true : false;
- if (!c.threadEnter(opType, isMutableComponent)) {
+ final int componentsCount = components.size();
+ for (int i = 0; i < componentsCount; i++) {
+ final ILSMComponent component = components.get(i);
+ boolean isMutableComponent = numEntered == 0 && component.getType() == LSMComponentType.MEMORY;
+ if (!component.threadEnter(opType, isMutableComponent)) {
break;
}
numEntered++;
@@ -202,14 +206,14 @@
throw e;
} finally {
if (!entranceSuccessful) {
- int i = 0;
- for (ILSMComponent c : components) {
+ final int componentsCount = components.size();
+ for (int i = 0; i < componentsCount; i++) {
+ final ILSMComponent component = components.get(i);
if (numEntered == 0) {
break;
}
- boolean isMutableComponent = i == 0 && c.getType() == LSMComponentType.MEMORY ? true : false;
- c.threadExit(opType, true, isMutableComponent);
- i++;
+ boolean isMutableComponent = i == 0 && component.getType() == LSMComponentType.MEMORY;
+ component.threadExit(opType, true, isMutableComponent);
numEntered--;
}
}
@@ -241,21 +245,22 @@
return true;
}
+ @CriticalPath
private void doExitComponents(ILSMIndexOperationContext ctx, LSMOperationType opType,
ILSMDiskComponent newComponent, boolean failedOperation) throws HyracksDataException {
- /**
+ /*
* FLUSH and MERGE operations should always exit the components
* to notify waiting threads.
*/
if (!ctx.isAccessingComponents() && opType != LSMOperationType.FLUSH && opType != LSMOperationType.MERGE) {
return;
}
- List<ILSMDiskComponent> inactiveDiskComponents = null;
+ List<ILSMDiskComponent> inactiveDiskComponents;
List<ILSMDiskComponent> inactiveDiskComponentsToBeDeleted = null;
try {
synchronized (opTracker) {
try {
- /**
+ /*
* [flow control]
* If merge operations are lagged according to the merge policy,
* flushing in-memory components are hold until the merge operation catches up.
@@ -368,13 +373,16 @@
}
}
+ @CriticalPath
private void exitOperationalComponents(ILSMIndexOperationContext ctx, LSMOperationType opType,
boolean failedOperation) throws HyracksDataException {
// First check if there is any action that is needed to be taken
// based on the state of each component.
- for (int i = 0; i < ctx.getComponentHolder().size(); i++) {
- ILSMComponent c = ctx.getComponentHolder().get(i);
- boolean isMutableComponent = i == 0 && c.getType() == LSMComponentType.MEMORY ? true : false;
+ final List<ILSMComponent> componentHolder = ctx.getComponentHolder();
+ final int componentsCount = componentHolder.size();
+ for (int i = 0; i < componentsCount; i++) {
+ final ILSMComponent c = componentHolder.get(i);
+ boolean isMutableComponent = i == 0 && c.getType() == LSMComponentType.MEMORY;
c.threadExit(opType, failedOperation, isMutableComponent);
if (c.getType() == LSMComponentType.MEMORY) {
switch (c.getState()) {
diff --git a/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/annotations/CriticalPath.java b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/annotations/CriticalPath.java
new file mode 100644
index 0000000..e092666
--- /dev/null
+++ b/hyracks-fullstack/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/annotations/CriticalPath.java
@@ -0,0 +1,36 @@
+/*
+ * 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.hyracks.util.annotations;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The method on which this annotation is applied has a very high call frequency during normal execution.
+ * Careful consideration should be taken with regard to the number of objects created and any expensive operations in
+ * there.
+ */
+@Documented
+@Target({ ElementType.METHOD })
+@Retention(RetentionPolicy.SOURCE)
+public @interface CriticalPath {
+}
\ No newline at end of file