Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*
!/**/
!**/*.java
!**/*.xml
!**/*.jar
!**/*.md
!.gitignore
Expand Down
80 changes: 77 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<maven.compiler.target>8</maven.compiler.target>
<maven.test.source>8</maven.test.source>
<maven.test.target>8</maven.test.target>
<jmh.version>1.21</jmh.version>
<maven-assembly-plugin.version>2.6</maven-assembly-plugin.version>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<maven-build-helper-plugin.version>1.12</maven-build-helper-plugin.version>
</properties>

<dependencies>
Expand All @@ -59,10 +63,16 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.0.1</version>
<version>3.1.0</version>
</dependency>
</dependencies>

Expand All @@ -79,6 +89,27 @@
</distributionManagement>
<build>
<plugins>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${maven-build-helper-plugin.version}</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/perf</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
Expand All @@ -94,11 +125,28 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>

<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
Expand All @@ -118,6 +166,32 @@
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>${maven-assembly-plugin.version}</version>
<configuration>
<descriptor>src/main/assembly/perf-tests.xml</descriptor>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<archive>
<manifest>
<mainClass>org.openjdk.jmh.Main</mainClass>
</manifest>
</archive>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
<profiles>
Expand Down Expand Up @@ -149,7 +223,7 @@
<configuration>
<aggregate>true</aggregate>
<additionalparam>-Xdoclint:none</additionalparam>
<additionalOptions>-Xdoclint:none</additionalOptions>
<!-- <additionalOptions>-Xdoclint:none</additionalOptions>-->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filipecosta90 you can just remove this duplication

</configuration>
<executions>
<execution>
Expand Down
28 changes: 28 additions & 0 deletions src/main/assembly/perf-tests.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>perf-tests</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.directory}/test-classes</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>**/*</include>
</includes>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
25 changes: 19 additions & 6 deletions src/main/java/io/redisearch/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ public boolean addDocument(Document doc, AddOptions options) {
public boolean[] addDocuments(Document... docs){
return addDocuments(new AddOptions(), docs);
}


/**
* Add a batch of documents to the index
Expand All @@ -369,11 +370,13 @@ public boolean[] addDocuments(Document... docs){
* @return true on success for each document
*/
public boolean[] addDocuments(AddOptions options, Document... docs){

try (Jedis conn = _conn()) {
Pipeline p = conn.pipelined();
for(Document doc : docs) {
addDocument(doc, options, conn);
addDocument(doc, options, p);
}
List<Object> objects = conn.getClient().getMany(docs.length);
List<Object> objects = p.syncAndReturnAll();
boolean[] results = new boolean[docs.length];
int i=0;
for(Object obj : objects) {
Expand All @@ -383,13 +386,24 @@ public boolean[] addDocuments(AddOptions options, Document... docs){
return results;
}
}


private void addDocument(Document doc, AddOptions options, Pipeline p) {
byte[][] args = addDocumentArgs(doc, options);
p.sendCommand(commands.getAddCommand(), args);

}

private BinaryClient addDocument(Document doc, AddOptions options, Jedis conn) {
byte[][] args = addDocumentArgs(doc, options);
return sendCommand(conn, commands.getAddCommand(), args);
}

private byte[][] addDocumentArgs(Document doc, AddOptions options) {
ArrayList<byte[]> args = new ArrayList<>();
args.add(endocdedIndexName);
args.add(SafeEncoder.encode(doc.getId()));
args.add(Protocol.toByteArray(doc.getScore()));

if (options.getNosave()) {
args.add(Keywords.NOSAVE.getRaw());
}
Expand All @@ -414,8 +428,7 @@ private BinaryClient addDocument(Document doc, AddOptions options, Jedis conn) {
Object value = ent.getValue();
args.add(value instanceof byte[] ? (byte[])value : SafeEncoder.encode(value.toString()));
}

return sendCommand(conn, commands.getAddCommand(), args.toArray(new byte[args.size()][]));
return args.toArray(new byte[args.size()][]);
}

/**
Expand Down
Loading