-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* we need to specify the version of jackson * GH-528 improve binary search in super blocks by keeping track of the estimated location of values in the underlying long array. This assumes that the values are ordered. * improved bit shifting in select1 by using Long.numberOfTrailingZeroes * only create the new Values if we are going to query the native store * reduce memory pressure * revert some changes based on review
- Loading branch information
1 parent
edd147d
commit 2492a84
Showing
10 changed files
with
393 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
...int-core/src/main/java/com/the_qa_company/qendpoint/core/util/disk/AbstractLongArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package com.the_qa_company.qendpoint.core.util.disk; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class AbstractLongArray implements LongArray { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
||
private static final int ESTIMATED_LOCATION_ARRAY_SIZE; | ||
|
||
static { | ||
// get total amount of memory that this java program is allowed to use | ||
long maxMemory = Runtime.getRuntime().maxMemory(); | ||
|
||
if (maxMemory >= 1024 * 1024 * 512) { | ||
ESTIMATED_LOCATION_ARRAY_SIZE = 1024 * 128; | ||
} else if (maxMemory >= 1024 * 1024 * 256) { | ||
ESTIMATED_LOCATION_ARRAY_SIZE = 1024 * 64; | ||
} else if (maxMemory >= 1024 * 1024 * 128) { | ||
ESTIMATED_LOCATION_ARRAY_SIZE = 1024 * 32; | ||
} else { | ||
ESTIMATED_LOCATION_ARRAY_SIZE = 1024 * 16; | ||
} | ||
|
||
} | ||
|
||
private final long[] estimatedLocationMax = new long[ESTIMATED_LOCATION_ARRAY_SIZE]; | ||
private final long[] estimatedLocationMin = new long[ESTIMATED_LOCATION_ARRAY_SIZE]; | ||
private final long[] estimatedLocation = new long[ESTIMATED_LOCATION_ARRAY_SIZE]; | ||
|
||
private int estimatedLocationBucketSize; | ||
|
||
long maxValue = 1; | ||
|
||
@Override | ||
public int getEstimatedLocationArrayBucketSize() { | ||
return estimatedLocationBucketSize; | ||
} | ||
|
||
private void updateEstimatedLocationArrayBucketSize() { | ||
int minBucketSize = (int) (maxValue / ESTIMATED_LOCATION_ARRAY_SIZE); | ||
// we want to have the next power of 2 | ||
int next = 1; | ||
while (next < minBucketSize) { | ||
next <<= 1; | ||
} | ||
this.estimatedLocationBucketSize = next; | ||
} | ||
|
||
@Override | ||
public long[] getEstimatedLocationArray() { | ||
return estimatedLocation; | ||
} | ||
|
||
@Override | ||
public long[] getEstimatedLocationArrayMin() { | ||
return estimatedLocationMin; | ||
} | ||
|
||
@Override | ||
public long[] getEstimatedLocationArrayMax() { | ||
return estimatedLocationMax; | ||
} | ||
|
||
@Override | ||
public void recalculateEstimatedValueLocation() { | ||
updateEstimatedLocationArrayBucketSize(); | ||
int estimatedLocationBucketSize = getEstimatedLocationArrayBucketSize(); | ||
long len = length(); | ||
boolean shouldLog = len > 1024 * 1024 * 2; | ||
if (shouldLog) { | ||
logger.info("Recalculating estimated location array 0%"); | ||
} | ||
|
||
for (int i = 0; i < len; i++) { | ||
long val = get(i); | ||
if (val == 0) { | ||
continue; | ||
} | ||
|
||
int index = (int) (val / estimatedLocationBucketSize + 1); | ||
estimatedLocationMax[index] = Math.max(estimatedLocationMax[index], i); | ||
if (estimatedLocationMin[index] == 0) { | ||
estimatedLocationMin[index] = i; | ||
} else { | ||
estimatedLocationMin[index] = Math.min(estimatedLocationMin[index], i); | ||
} | ||
estimatedLocation[index] = (estimatedLocationMax[index] + estimatedLocationMin[index]) / 2; | ||
|
||
if (shouldLog && i % (1024 * 1024) == 0) { | ||
logger.info("Recalculating estimated location array {}%", (int) Math.floor(100.0 / len * i)); | ||
} | ||
} | ||
|
||
if (shouldLog) { | ||
logger.info("Recalculating estimated location array 100%"); | ||
} | ||
} | ||
|
||
@Override | ||
public final void set(long index, long value) { | ||
maxValue = Math.max(maxValue, value); | ||
innerSet(index, value); | ||
} | ||
|
||
abstract protected void innerSet(long index, long value); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,4 +55,5 @@ public void resize(long newSize) throws IOException { | |
public void clear() { | ||
array.clear(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.