Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

latency tests #97

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public ResultSet callProcedure(String graphId, String procedure, List<String> ar

public ResultSet callProcedure(String graphId, String procedure, List<String> args , Map<String, List<String>> kwargs){

long startTime = System.nanoTime();
String preparedProcedure = Utils.prepareProcedure(procedure, args, kwargs);
long stopTime = System.nanoTime();
System.out.println("Prepare procedure " + procedure + " " + (stopTime - startTime)/1000000);
return query(graphId, preparedProcedure);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ protected Jedis getConnection() {
*/
@Override
protected ResultSet sendQuery(String graphId, String preparedQuery) {
long startTime = System.nanoTime();
Jedis conn = getConnection();
try {
List<Object> rawResponse = (List<Object>) conn.sendCommand(RedisGraphCommand.QUERY, graphId, preparedQuery, Utils.COMPACT_STRING);
return new ResultSetImpl(rawResponse, this, caches.getGraphCache(graphId));
long stopTime = System.nanoTime();
System.out.println("Server response time " + preparedQuery + " " + (stopTime - startTime)/1000000);

startTime = System.nanoTime();
ResultSet rs = new ResultSetImpl(rawResponse, this, caches.getGraphCache(graphId));
stopTime = System.nanoTime();
System.out.println("result set parsing " + preparedQuery + " " + (stopTime - startTime)/1000000);
return rs;
}
catch (JRedisGraphException rt) {
throw rt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GraphCacheList {

private final String graphId;
private final String procedure;
private final List<String> data = new CopyOnWriteArrayList<>();
private final List<String> data;

/**
*
Expand All @@ -26,6 +26,7 @@ class GraphCacheList {
public GraphCacheList(String graphId, String procedure) {
this.graphId = graphId;
this.procedure = procedure;
this.data = new CopyOnWriteArrayList<>();
}


Expand All @@ -36,11 +37,14 @@ public GraphCacheList(String graphId, String procedure) {
*/
public String getCachedData(int index, RedisGraph redisGraph) {
if (index >= data.size()) {
long startTime = System.nanoTime();
synchronized (data){
if (index >= data.size()) {
getProcedureInfo(redisGraph);
}
}
long stopTime = System.nanoTime();
System.out.println("Schema retrival" + (stopTime - startTime)/1000000);
}
return data.get(index);

Expand All @@ -50,7 +54,10 @@ public String getCachedData(int index, RedisGraph redisGraph) {
* Auxiliary method to parse a procedure result set and refresh the cache
*/
private void getProcedureInfo(RedisGraph redisGraph) {
long startTime = System.nanoTime();
ResultSet resultSet = redisGraph.callProcedure(graphId, procedure);
long stopTime = System.nanoTime();
System.out.println("getProcedureInfo " + procedure + " " + (stopTime - startTime)/1000000);
List<String> newData = new ArrayList<>();
int i = 0;
while (resultSet.hasNext()) {
Expand All @@ -61,5 +68,6 @@ private void getProcedureInfo(RedisGraph redisGraph) {
i++;
}
data.addAll(newData);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ public class RedisGraphCaches {

public GraphCache getGraphCache(String graphId){
if (!graphCaches.containsKey(graphId)){
long startTime = System.nanoTime();
graphCaches.putIfAbsent(graphId, new GraphCache(graphId));
long stopTime = System.nanoTime();
System.out.println("Graph Cache Create" + (stopTime - startTime)/1000000);
}
return graphCaches.get(graphId);
}
Expand Down
91 changes: 91 additions & 0 deletions src/test/java/com/redislabs/redisgraph/LatencyTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.redislabs.redisgraph;

import com.redislabs.redisgraph.impl.api.ContextedRedisGraph;
import com.redislabs.redisgraph.impl.api.RedisGraph;
import com.redislabs.redisgraph.impl.graph_cache.GraphCache;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.concurrent.CopyOnWriteArrayList;

public class LatencyTest {

private RedisGraphContextGenerator api;

// @Before
// public void createApi(){
// api = new RedisGraph("172.26.81.242", 7000);
// }
// @After
// public void deleteGraph() {
//
// api.deleteGraph("social");
// api.close();
// }

@Test
public void testLatency(){
api.query("social", "CREATE(:N {a:1})-[:E]->(:N2{b:2})");

long startTime = System.nanoTime();
api.query("social", "MATCH(n1)-[e]->(n2) RETURN *");
long stopTime = System.nanoTime();
System.out.println((stopTime - startTime)/1000000);


startTime = System.nanoTime();
api.query("social", "MATCH(n1)-[e]->(n2) RETURN *");
stopTime = System.nanoTime();
System.out.println((stopTime - startTime)/1000000);
}

@Test
public void testContextLatency() {
api.query("social", "CREATE(:N {a:1})-[:E]->(:N2{b:2})");
ContextedRedisGraph context = (ContextedRedisGraph) api.getContext();
long startTime = System.nanoTime();
context.query("social", "MATCH(n1)-[e]->(n2) RETURN *");
long stopTime = System.nanoTime();
System.out.println((stopTime - startTime)/1000000);

startTime = System.nanoTime();
context.query("social", "MATCH(n1)-[e]->(n2) RETURN *");
stopTime = System.nanoTime();
System.out.println((stopTime - startTime)/1000000);

api.query("social2", "CREATE(:N {a:1})-[:E]->(:N2{b:2})");
context = (ContextedRedisGraph) api.getContext();
startTime = System.nanoTime();
context.query("social2", "MATCH(n1)-[e]->(n2) RETURN *");
stopTime = System.nanoTime();
System.out.println((stopTime - startTime)/1000000);

startTime = System.nanoTime();
context.query("social2", "MATCH(n1)-[e]->(n2) RETURN *");
stopTime = System.nanoTime();
System.out.println((stopTime - startTime)/1000000);
}

@Test
public void testCacheCreationLatency(){
long startTime = System.nanoTime();
// CopyOnWriteArrayList[] lists = new CopyOnWriteArrayList[6];
// for (int i=0; i < 3; i++){
// lists[i] = new CopyOnWriteArrayList<>();
// }
new GraphCache("1");
long stopTime = System.nanoTime();
System.out.println((stopTime - startTime)/1000000);

startTime = System.nanoTime();
// for (int i=0; i < 3; i++){
// lists[i+3] = new CopyOnWriteArrayList<>();
// }
new GraphCache("2");

stopTime = System.nanoTime();
System.out.println((stopTime - startTime)/1000000);
}

}