VB_
VB_

Reputation: 45692

Unneeded verticle overhead and undeploy

Does Vert.x has any overhead for deployed verticles? Is there any reason to undeploy them after they become unneeded?

Pls look at MyVerticle - the only purpose of it is to do load on app launching, after loading this verticle is unneeded. Is it sufficient to call consumer.unregister()? Is there any reasons to undeploy 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(); 
        }
    }
}

Upvotes: 1

Views: 202

Answers (1)

Paulo Lopes
Paulo Lopes

Reputation: 5801

Verticles can be seen as applications running on Vert.x, deploying/undeploying only have a small overhead if for example you're doing high availability or failover. In this case Vert.x will need to keep track of deployed instances, monitor for failures and re-spawn verticles on other nodes, etc...

Undeploy will also allow you to perform any clean up (although you're not using it in your example) by calling the stop() method.

When not running with HA in mind undeploy will only allow you to recover any memory that was allocated by your Verticle but is not referenced anymore (plus the memory related to keep internal track of deployment verticles, which should be negletible as a single object reference).

Upvotes: 2

Related Questions