java - 不需要的 verticle 开销并取消部署

标签 java vert.x

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 上运行的应用程序,部署/取消部署只会有很小的开销,例如,如果您正在执行 high availability or failover 。在这种情况下,Vert.x 将需要跟踪已部署的实例、监视故障并在其他节点上重新生成 verticle,等等...

Undeploy 还允许您通过调用 stop() 来执行任何清理(尽管您在示例中没有使用它)。方法。

不使用 HA 运行时请记住,取消部署仅允许您恢复由 Verticle 分配但不再被引用的任何内存(加上与保持部署 verticle 的内部跟踪相关的内存,这作为单个对象引用应该可以忽略不计)。

关于java - 不需要的 verticle 开销并取消部署,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40293904/

相关文章:

java - Autowiring 接口(interface)无需注释即可工作

java - Vertx 将处理程序添加到 Spring 数据 API

java - Vert.x - 限制所有集群中的单实例 verticle

java - 将 Dao 作为静态成员存储在类中是否安全?

java - Android类之间的通信

java - 在这种情况下保存响应集的更好方法是什么?

java - 是否可以创建 java RAM 磁盘以与 java.io.* API 一起使用?

java - 在 TCP 服务器中使用 vertx Vertciles 的有效方法

java - 构建 REST Angular 应用程序的正确方法是什么?

java - 使用 Vertx "IAsyncResult"和 "EventBus consumer"之间的区别