-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perf improvements based on benchmarking (without all of the benchmark…
…ing code) (#75) Some internal changes based on a lot of benchmarking work. Deleted the benchmarking code from this branch and will merge it as a separate PR. See changelog entry.
- Loading branch information
1 parent
9d582a1
commit ac08eab
Showing
56 changed files
with
727 additions
and
451 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
-Dtests.heap.size=4G | ||
-Dtests.es.thread_pool.write.size=4 | ||
-Dtests.es.thread_pool.search.size=4 | ||
-Dtests.es.indices.query.bool.max_clause_count=4096 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ build | |
target | ||
release.md | ||
*.csv | ||
.minio/* | ||
!.minio/.keep | ||
|
||
# Ignore Gradle GUI config | ||
gradle-app.setting | ||
|
Empty file.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
version = "2.0.0-RC6" | ||
version = "2.5.2" | ||
maxColumn = 140 |
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
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
102 changes: 102 additions & 0 deletions
102
core/src/main/java/com/klibisz/elastiknn/storage/UnsafeSerialization.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,102 @@ | ||
package com.klibisz.elastiknn.storage; | ||
|
||
import sun.misc.Unsafe; | ||
|
||
import java.lang.reflect.Field; | ||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
/** | ||
* Uses the sun.misc.Unsafe classes to serialize int and float arrays for optimal performance based on benchmarking. | ||
* This is largely a simplification of the UnsafeInput and UnsafeOutput classes from the Kryo library. | ||
*/ | ||
public class UnsafeSerialization { | ||
|
||
public static final int numBytesInInt = 4; | ||
public static final int numBytesInFloat = 4; | ||
|
||
private static final UnsafeUtil u = AccessController.doPrivileged((PrivilegedAction<UnsafeUtil>) () -> { | ||
try { | ||
return new UnsafeUtil(); | ||
} catch (Exception ex) { | ||
throw new RuntimeException("Failed to initialize UnsafeSerialization", ex); | ||
} | ||
}); | ||
|
||
public static byte[] writeInt(final int i) { | ||
final int a = Math.abs(i); | ||
if (a <= Byte.MAX_VALUE) { | ||
final byte[] buf = new byte[1]; | ||
u.unsafe.putInt(buf, u.byteArrayOffset, i); | ||
return buf; | ||
} else if (a <= Short.MAX_VALUE) { | ||
final byte[] buf = new byte[2]; | ||
u.unsafe.putInt(buf, u.byteArrayOffset, i); | ||
return buf; | ||
} else { | ||
final byte[] buf = new byte[4]; | ||
u.unsafe.putInt(buf, u.byteArrayOffset, i); | ||
return buf; | ||
} | ||
} | ||
|
||
public static int readInt(final byte[] barr) { | ||
return u.unsafe.getInt(barr, u.byteArrayOffset); | ||
} | ||
|
||
/** | ||
* Writes ints to a byte array. | ||
* @param iarr ints to serialize. | ||
* @return Array of bytes with length (4 * iarr.length). | ||
*/ | ||
public static byte[] writeInts(final int[] iarr) { | ||
final int bytesLen = iarr.length * numBytesInInt; | ||
byte[] buf = new byte[bytesLen]; | ||
u.unsafe.copyMemory(iarr, u.intArrayOffset, buf, u.byteArrayOffset, bytesLen); | ||
return buf; | ||
} | ||
|
||
/** | ||
* Reads ints from a byte array. | ||
*/ | ||
public static int[] readInts(final byte[] barr, final int offset, final int length) { | ||
final int[] iarr = new int[length / numBytesInInt]; | ||
u.unsafe.copyMemory(barr, offset + u.byteArrayOffset, iarr, u.intArrayOffset, length); | ||
return iarr; | ||
} | ||
|
||
/** | ||
* Writes floats to a byte array. | ||
*/ | ||
public static byte[] writeFloats(final float[] farr) { | ||
final int bytesLen = farr.length * numBytesInFloat; | ||
final byte[] buf = new byte[bytesLen]; | ||
u.unsafe.copyMemory(farr, u.floatArrayOffset, buf, u.byteArrayOffset, bytesLen); | ||
return buf; | ||
} | ||
|
||
/** | ||
* Reads floats from a byte array. | ||
*/ | ||
public static float[] readFloats(final byte[] barr, final int offset, final int length) { | ||
final float[] farr = new float[length / numBytesInFloat]; | ||
u.unsafe.copyMemory(barr, offset + u.byteArrayOffset, farr, u.floatArrayOffset, length); | ||
return farr; | ||
} | ||
|
||
private static class UnsafeUtil { | ||
public final Unsafe unsafe; | ||
public final long intArrayOffset; | ||
public final long floatArrayOffset; | ||
public final long byteArrayOffset; | ||
public UnsafeUtil() throws NoSuchFieldException, IllegalAccessException { | ||
final Field f = sun.misc.Unsafe.class.getDeclaredField("theUnsafe"); | ||
f.setAccessible(true); | ||
unsafe = (Unsafe) f.get(null); | ||
intArrayOffset = unsafe.arrayBaseOffset(int[].class); | ||
floatArrayOffset = unsafe.arrayBaseOffset(float[].class); | ||
byteArrayOffset = unsafe.arrayBaseOffset(byte[].class); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.