These are good questions, but which are all answerable with a few simple experiments (which should be treated as more canonical than any information you get on the mailing list, documentation, or even source code!) Below I've spelled out the experiment you can do to answer your own questions:
On Tuesday, August 6, 2013 7:14:11 AM UTC-7,
jeremy....@hulu.com wrote:
I have a couple questions about how instances work mostly related to the JVM
- When I give the -instances option on the command line when running a vertical does it start each vertical in its own JVM or just as its own thread, i.e. '-instances 12' would be 12 JVMs or 12 threads with their own event loops?
With a sample module or verticle, run it with one and then multiple instances. Then check your native process count, perhaps with ps. How many do you see? If there is more than one then you have a JVM per verticle instance. [You won't see more than one.]
- How does 'static' variables/data work across verticals? Will one vertical see the same statically defined variables of another vertical? (if they are in the same JVM etc..)
Within a sample module, define two verticles. Deploy one instance of each. Define a class with a static, mutable member. Have both verticles print out the value of the static member then alter it's value. If the printout is the same, then there is classloader isolation between verticles. If they are different, then there isn't.
- How does the classpath of each vertical work, can I have multiple versions of the same library being used by different verticals at the same time?
The result of the previous experiment will answer that question.
- Is it possible to tweak the settings of the JVM that is running the verticals?
Okay, this one can't be answered by experiment, but only by either tracing the vertx invocation script or just knowing about the JVM. The short answer is "yes". The slightly longer answer is that you will need to set an environment variable called JVM_OPTS that will be passed to the 'java' process that vertx invokes.
As with most experiments, the hardest part of the problem is a) figuring out the experiment, and b) learning enough to actually carry it out! In this case, the "sample module" is the hard part, as the vertx-gradle-template or maven archetype (which I can't remember the name) is your best starting point. This begs the question: what is the simplest possible code you could write to do these experiments?
Here's my take:
ClassloaderTest.groovy:
class Foo{
static String bar = "a static value"
static boolean deployed = false
}
println "Classloader test loaded"
vertx.setPeriodic 500, {
println "hello world: ${Foo.bar}"
}
int i = 0
vertx.setPeriodic 1000, {
Foo.bar += "*"
if (i++ > 5) container.exit()
}
if (!Foo.deployed){
container.deployVerticle("ClassloaderTest.groovy")
Foo.deployed = true
}
run with:
vertx run ClassloaderTest.groovy -instances 1