不需要的 Verticle 开销和取消部署
Unneeded verticle overhead and undeploy
Vert.x 部署的 Verticle 有任何开销吗?在它们变得不需要后,是否有任何理由取消部署它们?
请查看 MyVerticle
- 它的唯一目的是在应用程序启动时执行 load
,加载后不需要此 Verticle。 调用consumer.unregister()
就够了吗?有什么理由取消部署 MyVerticle
?
public class MyVerticle extends AbstractVerticle {
private MessageConsummer consumer;
@Override
public void start() {
consumer = vertx.eventBus().consumer(AppConstants.SOME_ADDRESS, this::load);
}
@Override
public void load(Message message) {
LocalMap<Short, String> map = vertx.sharedData().getLocalMap(AppConstants.MAP_NAME);
try (
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(AppConstants.INDEX_PATH)))
) {
while (true) {
map.put(
in.readShort(),
in.readUTF()
);
}
} catch(EOFException eof) {
message.reply(AppConstants.SUCCESS);
} catch (IOException ioe) {
message.fail(100, "Fail to load index in memory");
throw new RuntimeException("There are no recovery policy", ioe);
} finally {
//is this sufficient or I need to undeploy them programmatically?
consumer.unregister();
}
}
}
Verticles 可以被视为 运行 在 Vert.x 上的应用程序,deploying/undeploying 如果您正在做 high availability or failover,则开销很小。在这种情况下 Vert.x 将需要跟踪已部署的实例、监控故障并在其他节点上重新生成 Verticle 等...
Undeploy 还允许您通过调用 stop()
方法执行任何清理(尽管您没有在您的示例中使用它)。
如果不考虑 运行 HA
取消部署将只允许您恢复由 Verticle 分配但不再被引用的任何内存(加上与保持内部部署跟踪相关的内存verticles,作为单个对象引用应该可以忽略不计)。
Vert.x 部署的 Verticle 有任何开销吗?在它们变得不需要后,是否有任何理由取消部署它们?
请查看 MyVerticle
- 它的唯一目的是在应用程序启动时执行 load
,加载后不需要此 Verticle。 调用consumer.unregister()
就够了吗?有什么理由取消部署 MyVerticle
?
public class MyVerticle extends AbstractVerticle {
private MessageConsummer consumer;
@Override
public void start() {
consumer = vertx.eventBus().consumer(AppConstants.SOME_ADDRESS, this::load);
}
@Override
public void load(Message message) {
LocalMap<Short, String> map = vertx.sharedData().getLocalMap(AppConstants.MAP_NAME);
try (
DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(AppConstants.INDEX_PATH)))
) {
while (true) {
map.put(
in.readShort(),
in.readUTF()
);
}
} catch(EOFException eof) {
message.reply(AppConstants.SUCCESS);
} catch (IOException ioe) {
message.fail(100, "Fail to load index in memory");
throw new RuntimeException("There are no recovery policy", ioe);
} finally {
//is this sufficient or I need to undeploy them programmatically?
consumer.unregister();
}
}
}
Verticles 可以被视为 运行 在 Vert.x 上的应用程序,deploying/undeploying 如果您正在做 high availability or failover,则开销很小。在这种情况下 Vert.x 将需要跟踪已部署的实例、监控故障并在其他节点上重新生成 Verticle 等...
Undeploy 还允许您通过调用 stop()
方法执行任何清理(尽管您没有在您的示例中使用它)。
如果不考虑 运行 HA
取消部署将只允许您恢复由 Verticle 分配但不再被引用的任何内存(加上与保持内部部署跟踪相关的内存verticles,作为单个对象引用应该可以忽略不计)。