Skip to content

Commit

Permalink
perf testing with Reakt
Browse files Browse the repository at this point in the history
  • Loading branch information
MammatusPlatypus committed Jul 1, 2016
1 parent f8b52ab commit bdd96a7
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

ext {
projectVersion = '1.10.0.RELEASE'
projectVersion = '1.10.6'
boonVersion = '0.5.7'
boonGroup = "io.advantageous.boon"
springFrameworkVersion = '4.2.5.RELEASE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
import io.advantageous.qbit.annotation.Service;
import io.advantageous.qbit.annotation.http.GET;
import io.advantageous.qbit.annotation.http.PUT;
import io.advantageous.qbit.reactive.Callback;
import io.advantageous.reakt.promise.Promise;
import io.advantageous.reakt.promise.Promises;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static io.advantageous.qbit.admin.ManagedServiceBuilder.managedServiceBuilder;

Expand All @@ -18,12 +24,62 @@ public class TradeService {

private long count;

final ExecutorService executorService = Executors.newFixedThreadPool(10);

@PUT("/trade")
public boolean t(final Trade trade) {
trade.getNm().hashCode();
trade.getAmt();
count++;
return true;
public void t(Callback<Boolean> cb, final Trade trade) {
executorService.submit(() -> {
trade.getNm().hashCode();
trade.getAmt();
count++;
cb.resolve(true);
try {
Thread.sleep(199);
} catch (InterruptedException e) {
e.printStackTrace();
}
});

}



@PUT("/a")
public void a(Callback<Boolean> cb, final Trade trade) {
trade.getNm().hashCode();
trade.getAmt();
count++;
cb.resolve(true);
}



@PUT("/trade2")
public Promise<Boolean> t2(final Trade trade) {
return Promises.invokablePromise(promise -> {
executorService.submit(() -> {
trade.getNm().hashCode();
trade.getAmt();
count++;
promise.resolve(true);
try {
Thread.sleep(201);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
});
}


@PUT("/trade2")
public Promise<Boolean> b(final Trade trade) {
return Promises.invokablePromise(promise -> {
trade.getNm().hashCode();
trade.getAmt();
count++;
promise.resolve(true);
});
}

@GET("/count")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package io.advantageous.qbit.example.perf.websocket;

import io.advantageous.qbit.reactive.Callback;
import io.advantageous.reakt.promise.Promise;

public interface TradeServiceAsync {


void a(Callback<Boolean> callback, final Trade trade);
void t(Callback<Boolean> callback, final Trade trade);
Promise<Boolean> b(final Trade trade);
Promise<Boolean> t2(final Trade trade);
void count(Callback<Long> callback);
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ public static void main(final String... args) {
totalCount += counts.get(c).get();
}

long seconds = (System.currentTimeMillis()-startTime)/1000;

puts("total", Str.num(totalCount),
"\tseconds", seconds,
"\telapsed time", Str.num(System.currentTimeMillis()-startTime),
"\trate", Str.num(totalCount/(System.currentTimeMillis()-startTime)*1000));
"\trate", Str.num(totalCount/seconds));
}

}
Expand All @@ -67,27 +70,37 @@ public static void main(final String... args) {
* @param count holds the total count
*/
private static void runCalls(final int numCalls, final AtomicInteger count) {
final Client client = clientBuilder().setUri("/")
//.setHost("192.168.0.1")
.setAutoFlush(false).build();
final Client client = clientBuilder().setUri("/").build();

final TradeServiceAsync tradeService = client.createProxy(TradeServiceAsync.class, "t");

client.startClient();

for (int call=0; call < numCalls; call++) {
tradeService.t(response -> {
tradeService.a(response -> {
if (response) {
count.incrementAndGet();
//System.out.println("count " + count.get());
}
}, new Trade("IBM", 1));

/** Apply some back pressure. */
if (call % 10 == 0) {
while (call - 5_000 > count.get()) {
Sys.sleep(10);
// tradeService.t2(new Trade("IBM", 1))
// .then(response -> {
// if (response) {
// count.incrementAndGet();
// }
// }
// )
// .catchError(Throwable::printStackTrace)
// .invoke();

if (call % 100 == 0) {
if (call > count.get() - 2000) {
Sys.sleep(1);
}
//flushServiceProxy(tradeService);
}

}

flushServiceProxy(tradeService);
Expand Down
2 changes: 1 addition & 1 deletion examples/standalone/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</appender>


<logger name="io.advantageous.qbit" level="DEBUG"/>
<logger name="io.advantageous.qbit" level="INFO"/>

<root level="INFO">
<appender-ref ref="STDOUT"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class QBitImplicitConversionsTest extends FlatSpec with Matchers {
}


"A Function" should "convert to a consumer" in {
CallbackBuilder.newCallbackBuilder().withErrorHandler((error: Throwable) => {})
}
// "A Function" should "convert to a consumer" in {
// CallbackBuilder.newCallbackBuilder().withErrorHandler((error: Throwable) => {})
// }



Expand Down

0 comments on commit bdd96a7

Please sign in to comment.