Skip to content
Browse files

Mini cleanup of perftests, performance boost in mutablestring.

  • Loading branch information...
1 parent 9d742f1 commit 42b8aa79eee0713ea5dc0773b9341cb98be8a922 @jakewins jakewins committed
View
8 src/main/java/org/neo4j/smack/MutableString.java
@@ -29,8 +29,12 @@ public MutableString(int initialCapacity)
public void append(char character)
{
- ensureCapacity(length+1);
- chars[length++] = character;
+ try {
+ chars[length++] = character;
+ } catch(ArrayIndexOutOfBoundsException e) {
+ ensureCapacity(length);
+ chars[length] = character;
+ }
}
public void setTo(MutableString value)
View
4 src/main/java/org/neo4j/smack/SmackServer.java
@@ -27,7 +27,7 @@
import org.jboss.netty.channel.group.ChannelGroup;
import org.jboss.netty.channel.group.DefaultChannelGroup;
import org.jboss.netty.channel.socket.ServerSocketChannelFactory;
-import org.jboss.netty.channel.socket.oio.OioServerSocketChannelFactory;
+import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
import org.neo4j.kernel.AbstractGraphDatabase;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.smack.handler.DatabaseWorkDivider;
@@ -86,7 +86,7 @@ public void start() {
// NETTY
channelFactory =
- new OioServerSocketChannelFactory(
+ new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(new DaemonThreadFactory("SocketMaster")),
Executors.newCachedThreadPool(new DaemonThreadFactory("SocketSlave")));
netty = new ServerBootstrap(channelFactory);
View
45 src/test/java/org/neo4j/smack/test/performance/LoadGeneratingRunnable.java
@@ -0,0 +1,45 @@
+package org.neo4j.smack.test.performance;
+
+import org.neo4j.smack.test.util.FixedRequestClient;
+import org.neo4j.smack.test.util.PerformanceRoutes;
+
+public class LoadGeneratingRunnable implements Runnable {
+
+
+ private FixedRequestClient client;
+ private long numRequestsToSend;
+ private boolean logStuff;
+ private int numWorkers;
+ private int requestsPerBatch = 1000;
+
+ public LoadGeneratingRunnable(boolean logStuff, long numRequestsToSend, int numWorkers){
+ client = new FixedRequestClient("localhost", 7473, PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION_AND_NO_INTROSPECTION, requestsPerBatch );
+ this.logStuff = logStuff;
+ this.numRequestsToSend = numRequestsToSend;
+ this.numWorkers = numWorkers;
+ }
+
+ @Override
+ public void run()
+ {
+ for(int i=0;i<numRequestsToSend;i+=requestsPerBatch)
+ {
+ client.sendBatch();
+ try {
+ // Used to help GC
+ Thread.sleep(0,1);
+ } catch(InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ if(i % 100000 == 0 && i != 0) {
+ if(logStuff) {
+ System.out.println("Sent: " + i * numWorkers + " requests");
+ }
+ client.waitForXResponses(i - 95000);
+ }
+ }
+
+ client.waitForXResponses(numRequestsToSend);
+ }
+
+}
View
30 src/test/java/org/neo4j/smack/test/performance/NetworkLatency.java
@@ -1,14 +1,13 @@
package org.neo4j.smack.test.performance;
-import java.net.URI;
import java.util.Date;
import javax.ws.rs.core.MediaType;
import org.neo4j.smack.Database;
import org.neo4j.smack.SmackServer;
+import org.neo4j.smack.test.util.FixedRequestClient;
import org.neo4j.smack.test.util.PerformanceRoutes;
-import org.neo4j.smack.test.util.PipelinedHttpClient;
import org.neo4j.test.ImpermanentGraphDatabase;
import com.sun.jersey.api.client.Client;
@@ -31,7 +30,7 @@
public class NetworkLatency {
private SmackServer server;
- private PipelinedHttpClient pipelineClient;
+ private FixedRequestClient pipelineClient;
public static void main(String [] args) {
NetworkLatency latency = new NetworkLatency();
@@ -43,22 +42,17 @@ public static void main(String [] args) {
private double test() {
try {
- int numRequests = 1000000;
+ int numRequests = 500000;
- startServer();
+ //startServer();
+
+ pipelineClient = new FixedRequestClient("localhost", 7473, PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION_AND_NO_INTROSPECTION, 1);
Date start = new Date();
- //sendXRequests("http://localhost:7473" + PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION, numRequests);
+ sendXRequests("http://localhost:7473" + PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION_AND_NO_INTROSPECTION, numRequests);
+ //sendXRequestsPipelined(numRequests);
Date end = new Date();
- // Pipelined calls
- pipelineClient = new PipelinedHttpClient("localhost", 7473);
-
- start = new Date();
- sendXRequests("http://localhost:7473" + PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION, numRequests);
- //sendXRequestsPipelined("http://localhost:7473" + PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION, numRequests);
- end = new Date();
-
long total = end.getTime() - start.getTime();
return ((double)total)/numRequests;
@@ -67,7 +61,7 @@ private double test() {
e.printStackTrace();
return 0d;
} finally {
- stopServer();
+ //stopServer();
}
}
@@ -78,11 +72,9 @@ private void sendXRequests(String uri, int numRequests) {
}
}
- private void sendXRequestsPipelined(String uri, int numRequests) throws InterruptedException {
- URI target = URI.create(uri);
+ private void sendXRequestsPipelined(int numRequests) throws InterruptedException {
for(int i=0;i<numRequests;i++) {
- //pipelineClient.handle(HttpMethod.GET, target, "");
- pipelineClient.sendRaw(1);
+ pipelineClient.sendBatch();
pipelineClient.waitForXResponses(i);
}
}
View
69 src/test/java/org/neo4j/smack/test/performance/NetworkThroughput.java
@@ -1,12 +1,11 @@
package org.neo4j.smack.test.performance;
-import java.net.URI;
import java.util.Date;
import org.neo4j.smack.Database;
import org.neo4j.smack.SmackServer;
+import org.neo4j.smack.test.util.FixedRequestClient;
import org.neo4j.smack.test.util.PerformanceRoutes;
-import org.neo4j.smack.test.util.PipelinedHttpClient;
import org.neo4j.test.ImpermanentGraphDatabase;
/**
@@ -14,7 +13,7 @@
* entire stack, including the network layer.
*
* High scores
- * smack, pipelined, 4 channels : 566 043.0758 req/second (2012-04-21, JH)
+ * smack, pipelined, 4 channels : 634 678.8525 req/second (2012-04-24, JH)
* smack, pipelined, 2 channels : 504 859.2704 req/second (2012-04-20, JH)
* smack, pipelined, single channel : 377 337.1318 req/second (2012-04-20, JH)
* jetty+jersey, pipelined, single channel : 17 470.6057 req/second (2012-04-18, JH)
@@ -25,7 +24,6 @@
public class NetworkThroughput {
private SmackServer server;
- private PipelinedHttpClient pipelineClient;
/**
* Gives throughput numbers over the network.
@@ -59,13 +57,11 @@ private NetworkThroughputResult test() {
NetworkThroughputResult result = new NetworkThroughputResult();
double totalSeconds = 0;
try {
- Thread.sleep(1000 * 20);
+ //Thread.sleep(1000 * 20);
//long numRequests = 1755028000l;
long numRequests = 10000000l;
- startServer();
-
- pipelineClient = new PipelinedHttpClient("localhost", 7473);
+ //startServer();
// Simple HTTP calls
@@ -74,11 +70,9 @@ private NetworkThroughputResult test() {
result.simpleHttpCalls = ((double)numRequests)/totalSeconds;
// Pipelined calls
- pipelineClient.responseHandler.responseCount.set(0);
System.out.println("Warming up..");
sendXRequestsPipelined("http://localhost:7473" + PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION, 100000);
- pipelineClient.responseHandler.responseCount.set(0);
System.out.println("Running test..");
//totalSeconds = sendXRequestsPipelined("http://localhost:7473" + PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION, numRequests);
@@ -92,7 +86,7 @@ private NetworkThroughputResult test() {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
- stopServer();
+ //stopServer();
}
}
@@ -102,37 +96,7 @@ private double sendXRequestsPipelinedMultiThreaded(String uri,
Thread [] runnables = new Thread[numThreads];
final long numRequestsPerThread = (long) numRequests / numThreads;
for(int i=0;i<numThreads;i++) {
- runnables[i] = new Thread(new Runnable(){
-
- private PipelinedHttpClient client;
-
- {
- client = new PipelinedHttpClient("localhost", 7473);
- }
-
- @Override
- public void run()
- {
- for(int i=0;i<numRequestsPerThread;i+=20) {
- //pipelineClient.handle(HttpMethod.GET, target, "");
- client.sendRaw(20);
- try {
- // Used to help profiling
- Thread.sleep(10);
- } catch(InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- try
- {
- client.waitForXResponses(numRequestsPerThread);
- } catch (InterruptedException e)
- {
- throw new RuntimeException(e);
- }
- }
- });
+ runnables[i] = new Thread(new LoadGeneratingRunnable(i == 0, numRequestsPerThread, numThreads));
}
Date start = new Date();
@@ -148,25 +112,28 @@ public void run()
return (end.getTime() - start.getTime()) / 1000.0d;
}
- private double sendXRequests(String uri, int numRequests) throws InterruptedException {
- URI target = URI.create(uri);
+ private double sendXRequests(int numRequests) throws InterruptedException {
+ FixedRequestClient client = new FixedRequestClient("localhost", 7473, PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION_AND_NO_INTROSPECTION, 1);
+
Date start = new Date();
for(int i=0;i<numRequests;i+=1) {
- //pipelineClient.handle(HttpMethod.GET, target, "");
- pipelineClient.sendRaw(1);
- pipelineClient.waitForXResponses(i);
+ client.sendBatch();
+ client.waitForXResponses(i);
}
Date end = new Date();
+ client.close();
return (end.getTime() - start.getTime()) / 1000.0d;
}
private double sendXRequestsPipelined(String uri, long numRequests) throws InterruptedException {
+ int requestsPerBatch = 1000;
+ FixedRequestClient client = new FixedRequestClient("localhost", 7473, PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION_AND_NO_INTROSPECTION, requestsPerBatch);
Date start = new Date();
- for(int i=0;i<numRequests;i+=20) {
- //pipelineClient.handle(HttpMethod.GET, target, "");
- pipelineClient.sendRaw(20);
+ for(int i=0;i<numRequests;i+=requestsPerBatch) {
+ client.sendBatch();
}
- pipelineClient.waitForXResponses(numRequests);
+ client.waitForXResponses(numRequests);
+ client.close();
Date end = new Date();
return (end.getTime() - start.getTime()) / 1000.0d;
}
View
29 src/test/java/org/neo4j/smack/test/performance/PerfTestServer.java
@@ -0,0 +1,29 @@
+package org.neo4j.smack.test.performance;
+
+import org.neo4j.smack.Database;
+import org.neo4j.smack.SmackServer;
+import org.neo4j.smack.test.util.PerformanceRoutes;
+import org.neo4j.test.ImpermanentGraphDatabase;
+
+public class PerfTestServer {
+
+ private static SmackServer server;
+
+ public static void main(String [] args) {
+ server = new SmackServer("localhost", 7473, new Database(new ImpermanentGraphDatabase()));
+ server.addRoute("",new PerformanceRoutes());
+ server.start();
+
+ try
+ {
+ Thread.sleep(1000 * 60 * 60 * 24 * 7);
+ } catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ server.stop();
+ }
+
+}
View
75 src/test/java/org/neo4j/smack/test/util/FixedRequestClient.java
@@ -0,0 +1,75 @@
+package org.neo4j.smack.test.util;
+
+import java.io.UnsupportedEncodingException;
+
+import org.jboss.netty.buffer.ChannelBuffer;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.handler.codec.http.HttpHeaders;
+import org.jboss.netty.handler.codec.http.HttpVersion;
+
+/**
+ * A http client for performance testing,
+ * builds a byte array upon instantiation with
+ * a fixed request to send, saving precious microseconds.
+ */
+public class FixedRequestClient extends PipelinedHttpClient {
+
+ private ChannelBuffer buf;
+ public FixedRequestClient(String host, int port, String path, int numRequestsPerBatch)
+ {
+ super(host, port);
+ initRequestBuffer(numRequestsPerBatch, path, host);
+ }
+
+ private void initRequestBuffer(int numRequestsPerBatch, String path, String host)
+ {
+ buf = ChannelBuffers.dynamicBuffer(100);
+ try {
+ for(int i=0;i<numRequestsPerBatch;i++) {
+ addRequestTo(buf, path, host);
+ }
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void sendBatch() {
+ channel.write(buf);
+ }
+
+ private void addRequestTo(ChannelBuffer buf, String path, String host) throws UnsupportedEncodingException
+ {
+ buf.writeBytes("GET".getBytes("ASCII"));
+ buf.writeByte(SP);
+ buf.writeBytes(path.getBytes("ASCII"));
+ buf.writeByte(SP);
+ buf.writeBytes(HttpVersion.HTTP_1_1.toString().getBytes("ASCII"));
+ buf.writeByte(CR);
+ buf.writeByte(LF);
+
+ buf.writeBytes(HttpHeaders.Names.HOST.getBytes("ASCII"));
+ buf.writeByte(COLON);
+ buf.writeByte(SP);
+ buf.writeBytes(host.getBytes("ASCII"));
+ buf.writeByte(CR);
+ buf.writeByte(LF);
+
+ buf.writeBytes(HttpHeaders.Names.CONNECTION.getBytes("ASCII"));
+ buf.writeByte(COLON);
+ buf.writeByte(SP);
+ buf.writeBytes("keep-alive".getBytes("ASCII"));
+ buf.writeByte(CR);
+ buf.writeByte(LF);
+
+ buf.writeBytes(HttpHeaders.Names.CONTENT_LENGTH.getBytes("ASCII"));
+ buf.writeByte(COLON);
+ buf.writeByte(SP);
+ buf.writeBytes("0".getBytes("ASCII"));
+ buf.writeByte(CR);
+ buf.writeByte(LF);
+
+ buf.writeByte(CR);
+ buf.writeByte(LF);
+ }
+
+}
View
87 src/test/java/org/neo4j/smack/test/util/PipelinedHttpClient.java
@@ -2,7 +2,6 @@
import static org.jboss.netty.channel.Channels.pipeline;
-import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.nio.charset.Charset;
@@ -176,19 +175,19 @@ private void skipControlCharacters(ChannelBuffer buffer) {
}
}
- private String readLine(ChannelBuffer buffer, int maxLineLength) throws TooLongFrameException {
- StringBuilder sb = new StringBuilder(64);
+ private void readLine(ChannelBuffer buffer, int maxLineLength) throws TooLongFrameException {
+ //StringBuilder sb = new StringBuilder(64);
int lineLength = 0;
while (true) {
byte nextByte = buffer.readByte();
if (nextByte == CR) {
nextByte = buffer.readByte();
if (nextByte == LF) {
- return sb.toString();
+ return;
}
}
else if (nextByte == LF) {
- return sb.toString();
+ return;
}
else {
if (lineLength >= maxLineLength) {
@@ -201,7 +200,7 @@ else if (nextByte == LF) {
" bytes.");
}
lineLength ++;
- sb.append((char) nextByte);
+ //sb.append((char) nextByte);
}
}
}
@@ -228,17 +227,13 @@ public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
}
}
- private Channel channel;
+ protected Channel channel;
private ClientBootstrap bootstrap;
public HttpResponseHandler responseHandler = new HttpResponseHandler();
- private ChannelBuffer buf;
-
public PipelinedHttpClient(String host, int port) {
- initRequestBuffer();
-
// Configure the client.
bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(
Executors.newCachedThreadPool(),
@@ -259,18 +254,6 @@ public PipelinedHttpClient(String host, int port) {
}
}
- private void initRequestBuffer()
- {
- buf = ChannelBuffers.dynamicBuffer(100);
- try {
- for(int i=0;i<20;i++) {
- addRequestTo(buf);
- }
- } catch(Exception e) {
- throw new RuntimeException(e);
- }
- }
-
public ChannelFuture handle(HttpMethod method, URI uri, String payload) {
if(responseHandler.lastException != null) {
@@ -295,65 +278,19 @@ public ChannelFuture handle(HttpMethod method, URI uri, String payload) {
// Send the HTTP request.
return channel.write(request);
}
-
- public void sendRaw(int reqsInMessage) {
-// ChannelBuffer buf = ChannelBuffers.dynamicBuffer(channel.getConfig().getBufferFactory());
-//
-// try
-// {
-// for(int i=0;i<reqsInMessage;i++)
-// addRequestTo(buf);
-// } catch (UnsupportedEncodingException e)
-// {
-// throw new RuntimeException(e);
-// }
-
- channel.write(buf);
- }
-
- private void addRequestTo(ChannelBuffer buf) throws UnsupportedEncodingException
- {
- buf.writeBytes("GET".getBytes("ASCII"));
- buf.writeByte(SP);
- buf.writeBytes(PerformanceRoutes.NO_SERIALIZATION_AND_NO_DESERIALIZATION_AND_NO_INTROSPECTION.getBytes("ASCII"));
- buf.writeByte(SP);
- buf.writeBytes(HttpVersion.HTTP_1_1.toString().getBytes("ASCII"));
- buf.writeByte(CR);
- buf.writeByte(LF);
-
- buf.writeBytes(HttpHeaders.Names.HOST.getBytes("ASCII"));
- buf.writeByte(COLON);
- buf.writeByte(SP);
- buf.writeBytes("localhost".getBytes("ASCII"));
- buf.writeByte(CR);
- buf.writeByte(LF);
-
- buf.writeBytes(HttpHeaders.Names.CONNECTION.getBytes("ASCII"));
- buf.writeByte(COLON);
- buf.writeByte(SP);
- buf.writeBytes("keep-alive".getBytes("ASCII"));
- buf.writeByte(CR);
- buf.writeByte(LF);
-
- buf.writeBytes(HttpHeaders.Names.CONTENT_LENGTH.getBytes("ASCII"));
- buf.writeByte(COLON);
- buf.writeByte(SP);
- buf.writeBytes("0".getBytes("ASCII"));
- buf.writeByte(CR);
- buf.writeByte(LF);
-
- buf.writeByte(CR);
- buf.writeByte(LF);
- }
// Quick hack to wait for responses
- public void waitForXResponses(long count) throws InterruptedException {
+ public void waitForXResponses(long count) {
while(responseHandler.responseCount.get() < count) {
if(responseHandler.lastException != null) {
responseHandler.lastException.printStackTrace();
throw new RuntimeException(responseHandler.lastException);
}
- Thread.sleep(0, 10);
+ try {
+ Thread.sleep(0, 10);
+ } catch(Exception e) {
+ throw new RuntimeException(e);
+ }
}
}

0 comments on commit 42b8aa7

Please sign in to comment.
Something went wrong with that request. Please try again.