final HttpServerRequest event = ...
Node node = NodeBuilder.nodeBuilder().clusterName("test").build();
Client client = node.client();
client.prepareIndex().setSource("").execute(new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse response) {
vertx.runOnContext(new Handler<Void>() {
@Override
public void handle(Void v) {
event.response().end("success");
}
});
}
@Override
public void onFailure(Throwable e) {
// TODO Auto-generated method stub
}
});
client.close();
It was mentioned that elasticsearch works better than mongodb and has a nice async java driver. After looking at elasticsearch, it really does seem like a better mongodb (better indexing/searching, better clustering with quorums, versioning of documents for keeping data consistent, etc) and the async driver is nicely made. However, it looks like the async driver runs its own thread pool. Is this alright or would it be a good idea to somehow replace the elasticsearch threadpool for a vertx worker pool somehow?
Assuming the elasticsearch threadpool is OK (it seems to run fine), is this the correct way to handle the responses? I wrapped the response using runOnContext to make sure the result returns onto the correct vertx thread...
final HttpServerRequest event = ...
Node node = NodeBuilder.nodeBuilder().clusterName("test").build();
Client client = node.client();
client.prepareIndex().setSource("").execute(new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse response) {
vertx.runOnContext(new Handler<Void>() {
@Override
public void handle(Void v) {
event.response().end("success");
}
});
}
@Override
public void onFailure(Throwable e) {
// TODO Auto-generated method stub
}
});
client.close();
Also, redeploying the module a few times caused a permgen error, likely because elasticsearch has so many classes. To solve this, I was thinking of putting elasticsearch into its own module with resident set to true so that it doesn't get reloaded. http://vertx.io/mods_manual.html#resident
Is this the right way to handle it? I can't think of any other way around the permgen issue.
--
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/groups/opt_out.
After more investigation, Elasticsearch doesn't seem to be a good fit for vert.x. While the driver is async, it handles this by creating threadpools... and there doesn't seem to be any way to replace them. The callback function generally gets called on the thread of one of the threadpools and so vertx.runOnContext doesn't work as there is no context.
You can bypass it a bit by storing the context:
final Context context = vertx.currentContext();
and then inside the callback
context.runOnContext(new Handler<Void>() {
This works, but I'm assuming vert.x is not meant to be used this way
and that you could get errors as multiple threads hit the non-thread safe context. Right ?
So it looks like using elasticsearch as a new async database driver on vert.x is not a good idea after all.
On Wednesday, January 8, 2014 1:58:47 PM UTC+2, Ryan Chazen wrote:It was mentioned that elasticsearch works better than mongodb and has a nice async java driver. After looking at elasticsearch, it really does seem like a better mongodb (better indexing/searching, better clustering with quorums, versioning of documents for keeping data consistent, etc) and the async driver is nicely made. However, it looks like the async driver runs its own thread pool. Is this alright or would it be a good idea to somehow replace the elasticsearch threadpool for a vertx worker pool somehow?
Assuming the elasticsearch threadpool is OK (it seems to run fine), is this the correct way to handle the responses? I wrapped the response using runOnContext to make sure the result returns onto the correct vertx thread...
final HttpServerRequest event = ...
Node node = NodeBuilder.nodeBuilder().clusterName("test").build();
Client client = node.client();
client.prepareIndex().setSource("").execute(new ActionListener<IndexResponse>() {
@Override
public void onResponse(IndexResponse response) {
vertx.runOnContext(new Handler<Void>() {
@Override
public void handle(Void v) {
event.response().end("success");
}
});
}
@Override
public void onFailure(Throwable e) {
// TODO Auto-generated method stub
}
});
client.close();
Also, redeploying the module a few times caused a permgen error, likely because elasticsearch has so many classes. To solve this, I was thinking of putting elasticsearch into its own module with resident set to true so that it doesn't get reloaded. http://vertx.io/mods_manual.html#resident
Is this the right way to handle it? I can't think of any other way around the permgen issue.
--
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/kVtP9qNJz_Y/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to vertx+un...@googlegroups.com.
Sounds creat… Keep us posted!