Hi,--I want to understand the relationship between the verticle instance - event loop - context - cpu cores. From the documents I understood that each vertcile instance will have one event loop mapped too. In a sample program I tried with a single verticle instance I was able to max out all the cpu cores in the machine. So, does it mean that single event loop is able to use all the cpu cores in the machine? If this is the case when should I have to increase the verticle instance number when I start the vertx instance. Is there a guide or formula to figure out how many instances of verticle is optimum to spin out based on the number of cores or any?
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+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/4f37b14a-20ca-409e-ae04-2b4b5598c7ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Below is the program I used to check whether the vertx with single event loop can make use of all the cores in the machine. When I execute this and saw the CPU usage using "htop" I could see 8 cores put to work. So it all happening by one thread/one event loop?public class VertxPerformanceTest extends AbstractVerticle {
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
DeploymentOptions deploymentOptions = new DeploymentOptions();
deploymentOptions.setInstances(1);
vertx.deployVerticle("com.tesco.cec.VertxPerformanceTest", deploymentOptions);
}
@Override
public void start() throws Exception {
super.start();
HttpClient httpClient = vertx.createHttpClient();
IntStream.rangeClosed(1, 100).forEach(delay -> {
vertx.setPeriodic(1, idx -> {
HttpClientRequest req = httpClient.request(HttpMethod.GET, 80, "www.amazon.in", "/");
req.toObservable().
flatMap(resp -> {
//System.out.println(resp.statusCode());
return resp.toObservable();
}).
subscribe();
req.end();
});
});
}
}
On Monday, March 27, 2017 at 2:07:27 PM UTC+5:30, Thomas Segismont wrote:
Each verticle instance is assigned a different event loop. The context is an execution abstraction which can either be backed by an event loop (standard verticle) or a pool of worker threads (worker verticle). Different verticles (and thus context) can be backed by the same event loop. An event loop is really just a thread. The operating system decides where the thread will run. It could start on one core and move to another core (or socket) later. Vert.x does not set thread affinity (there is not even Java APIs for this).So, your verticle instance could run on different cores, but is seems strange that it consumes 100% cpu on all cores.
As a rule of thumb, you can deploy a verticle instance per core. But since verticle code is very different from one project to another, it's best to measure the results with some performance testing.
2017-03-27 8:34 GMT+02:00 Pradp <pradeep....@gmail.com>:
Hi,I want to understand the relationship between the verticle instance - event loop - context - cpu cores. From the documents I understood that each vertcile instance will have one event loop mapped too. In a sample program I tried with a single verticle instance I was able to max out all the cpu cores in the machine. So, does it mean that single event loop is able to use all the cpu cores in the machine? If this is the case when should I have to increase the verticle instance number when I start the vertx instance. Is there a guide or formula to figure out how many instances of verticle is optimum to spin out based on the number of cores or any?
--
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.
public class VertxPerformanceTest
extends AbstractVerticle {
public static void main(String[]
args) {
Vertx vertx = Vertx.vertx();
DeploymentOptions
deploymentOptions = new DeploymentOptions();
deploymentOptions.setInstances(1
);
vertx.deployVerticle("VertxPerformanceTest",
deploymentOptions);
}
@Override
public void start()
throws Exception {
super.start();
HttpClient httpClient = vertx.createHttpClient();
IntStream.rangeClosed(1, 100).forEach(delay
-> {
vertx.setPeriodic(1,
idx -> {
HttpClientRequest req = httpClient.request(HttpMethod.GET,
80,
"localhost", "/");
req.toObservable().
flatMap(resp
-> {
//System.out.println(resp.statusCode());
return
resp.toObservable();
}).
subscribe();
req.end();
});
});
}
}
Each verticle instance is assigned a different event loop. The context is an execution abstraction which can either be backed by an event loop (standard verticle) or a pool of worker threads (worker verticle). Different verticles (and thus context) can be backed by the same event loop. An event loop is really just a thread. The operating system decides where the thread will run. It could start on one core and move to another core (or socket) later. Vert.x does not set thread affinity (there is not even Java APIs for this).So, your verticle instance could run on different cores, but is seems strange that it consumes 100% cpu on all cores.
As a rule of thumb, you can deploy a verticle instance per core. But since verticle code is very different from one project to another, it's best to measure the results with some performance testing.
2017-03-27 8:34 GMT+02:00 Pradp <pradeep....@gmail.com>:
Hi,I want to understand the relationship between the verticle instance - event loop - context - cpu cores. From the documents I understood that each vertcile instance will have one event loop mapped too. In a sample program I tried with a single verticle instance I was able to max out all the cpu cores in the machine. So, does it mean that single event loop is able to use all the cpu cores in the machine? If this is the case when should I have to increase the verticle instance number when I start the vertx instance. Is there a guide or formula to figure out how many instances of verticle is optimum to spin out based on the number of cores or any?
--
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.
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpClient;
import io.vertx.ext.web.Router;
import java.math.BigInteger;
import java.util.stream.IntStream;
/**
* Created by gts9 on 04/04/17.
*/
public class PerformanceTest extends AbstractVerticle{
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
DeploymentOptions deploymentOptions = new DeploymentOptions();
deploymentOptions.setInstances(1
);
vertx.deployVerticle("PerformanceTest", deploymentOptions);
}
@Override
public void start() throws Exception {
super.start();
Router router = Router.router(vertx);
HttpClient httpClient = vertx
.createHttpClient();
IntStream.rangeClosed(1, 100000).forEach(delay -> {
vertx.setPeriodic(1, idx -> {
keepCpuBusy();
});
});
}
private void keepCpuBusy() {
BigInteger factValue = BigInteger.ONE;
long t1 = System.nanoTime();
for (int i = 2; i <= 100000; i++) {
factValue = factValue.multiply(BigInteger.valueOf(i));
}
long t2 = System.nanoTime();
String result = "CPU Id: Service Time(ms)=" + ((double) (t2 - t1) / 1000000);
System.out.println(result);
}
}
Now the CPU utilisation matches to the verticle instances in a way
Thanks a lot Jez P.
To end this discussion I like to clarify on one point. It is advertised that vertx uses multi reactor pattern and uses all the cores of machine not like node js.
But here I see only one event loop is created when there is only one verticle instance. If I increase the number of instances the event loop count increases
and uses all the cores. My understanding by reading the docs and presentation which shows multiple event loop that it will be spun by default based on the cores
to utilise all the cores. At least that is what the impression I get and I checked with few of my colleagues too. If we have to increase the instances to make it happen
how is it different from node js? I have to do the same
in node js to spin more process using compute node module to make use of all cores. Only difference I could see here in vertx it is natively built in but the developer effort remains the same in a way.
Does it mean that the single process here can use all the cores in contrast to node there are multiple processes? How does the comparison works?