@Override
public void start() {
JsonObject config = container.config();
container.deployWorkerVerticle(UserCreator.class.getName(), config, 1, false,
v -> container.deployVerticle(ResourceCreator.class.getName(), config,
v2 -> container.deployVerticle(PerformanceTests.class.getName(), config)));
this.vertx.eventBus().registerHandler(ERROR_HANDLER, errorMessage -> {
container.logger().error("ERROR " + errorMessage.body());
container.exit();
});
} private HttpClient httpClient; private HttpClient getHttpClient() { if (httpClient == null) { httpClient = vertx.createHttpClient() .setHost(container.config().getString("host", "localhost")) .setPort(container.config().getInteger("port", 3000)); } return httpClient; } ResourceStatusHandler handler = new ResourceStatusHandler(auth, id, System.currentTimeMillis());
container.logger().debug("Http status request sent"); getHttpClient().get("/resource/" + id, handler) .exceptionHandler(new HttpExceptionHandler(vertx)) .putHeader("Authorization", auth) .end(); private class ResourceStatusHandler implements Handler<HttpClientResponse> { private long startedAt; private String auth; private String id;
public ResourceStatusHandler(String auth, String id, long startedAt) { this.auth = auth; this.id = id; this.startedAt = startedAt; }
@Override public void handle(HttpClientResponse event) { if (event.statusCode() != 200) { Util.reportHttpError(vertx, event); return; }
container.logger().debug("Got status in " + (System.currentTimeMillis() - this.startedAt)); event.bodyHandler(body -> { JsonObject bodyJson = new JsonObject(body.toString());
String state = bodyJson.getString("state");
if ("PROCESSING".equals(state)) { vertx.setTimer(500, l -> getResourceStatus(id, auth)); } else if ("FINISHED".equals(state)) { numberOfFinishedResources++; resources.get(id).finishedAt(System.currentTimeMillis()); } }); } }--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/LiAvgym4oXo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
- worker verticle simulates posting a big number of tasks on server. Because it has potentially long running for loop, I made it a worker verticle instead of a "normal" oneIn application on github:Thanks for quick reply.The application on github (let's call it application G) is supposed to simulate a real life application (application P) that I'm trying to build at work. I want to use the P application to carry on performance tests of yet another application (application S). Basically the idea is to post a big number of long running tasks on the server, long polling for the status of the task and once it's finished write to logs how long it took to finish the task.
"I can't see anything in the code that is blocking, so I can't see any reason why this should be a worker verticle. What makes you think the for loop is long running?"I made it a worker verticle because of potentially long running for loop. In every iteration it perform non-blocking operation, but even though I guess it can take some time to send thousands of HTTP request and set event handlers for the response.
"But it seems to me the event bus communication is redundant - you could probably do everything in a single verticle and scale up with number instances"This is a way to go. I'll try to make it simpler (although the real life example is more complicated).
--