Vertx扩展每个线程的实例数 [英] Vertx scaling the number of instances per thread

查看:667
本文介绍了Vertx扩展每个线程的实例数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Vert.x是用于在JVM上构建响应式应用程序的工具包.

Vert.x is a tool-kit for building reactive applications on the JVM.

我想对基于JVM的自动可伸缩RESTful后端API使用vertx.

I want to use vertx for JVM-based auto-scalable RESTful backend API.

到目前为止,我从文档中发现,默认情况下,它需要计算机中的内核数,假设您有N个内核并为每个内核创建N个线程,每个线程是一个事件总线,每个线程包含vertx实例. 问题是,Vertx如何控制实例数量?基于负载压力?

So far what I've found from the documentation, that it takes by default the number of cores in your machine, let's say you have N cores and creates N threads for each core, each thread is a event bus, each thread contains vertx instances. The question is, how does Vertx control the number of instances? based on load-pressure?

关于控制通过给定线程运行的Verticles数量的问题我仍然没有得到. 请帮助清除此问题. 假设计算机具有4个核心,并且我编写了两个扩展为AbstractVerticle的类:

This thing about control over the number of Verticles running withing a given thread i still don't get. Please help to clearify this thing. Let's assume machine has 4 cores and I have written two classes extended as AbstractVerticle:

1)让一个数据库数据检索器(我们称其为RETRIEVER或"R")

1) let one be some DB data retriever (let's call it RETRIEVER or "R")

2)另一个可以说是某个转换器(我们称其为CONVERTER或"C")

2) another one let's say is some converter (let's call it CONVERTER or "C")

现在,我使用vertx运行或编译并运行:

Now I run with vertx or compile and run:

$ java -jar resolver.jar

$ java -jar retriever.jar

$ java -jar converter.jar

$ java -jar converter.jar

因此,由于我们有4个内核,因此Vertx在启动时将为每个内核创建4个线程.

So since we have 4 cores, on start Vertx will create 4 threads per core.

问题#1:

多少只猎犬&默认情况下,每个线程中都有转换器实例吗?我猜每个线程一个实例吗? 正确的?因此,总共有4个核,总共有4个检索器实例和4个inst.转换器?正确吗?

how many retriever & converter instances will we have by default in each thread? I guess it's one instance per thread? right? So we'll have for 4 cores in total 4 instances of retriever and 4 inst. of converter? Correct?

问题#2:

如果负载压力增加,而调用RETRIEVER("R")和COVERTER("C")的次数增加 (从1.000到1.000.000呼叫)Vertx是否将自动管理为处理增加的系统呼叫次数所需的"R"和"C"实例数量?

in case of increasing load-pressure with increasing number of calls to RETRIEVER ("R") and COVERTER ("C") (from 1.000 to 1.000.000 calls) will Vertx automatically manage the number of "R" and "C" instances required to handle increased number of calls to our System ?

在stackoverflow上,存在一个类似问题的问题: 我可以在Vert上设置容量吗.x HTTP请求队列?

On stackoverflow there is a question with a similar problem: Can I set a capacity on the Vert.x HTTP request queue?

Jordan Halterman建议:还请注意,您可以跨多个垂直实例扩展HTTP服务器以处理更多请求.在这种情况下,您可以使用静态变量或共享数据在各个实例之间共享信号量."

Jordan Halterman suggests: "Note also that you can scale your HTTP server across multiple verticle instances in order to handle more requests. In this case you can either use static variables or shared data to share a semaphore across the instances."

问题#3:

但是您如何准确地缩放您的verticle实例以处理更多请求?我在文档中找不到这个.

But how do you exactly do scale your verticle instances to handle more requests ? I couldn't find this in documentation.

我非常感谢您的帮助!

推荐答案

您误解了文档.

首先,只有一个事件总线(当以群集模式启动Vert.x时,它在Vert.x实例之间共享).它的作用是允许消息在您的各个顶点之间传递通信方式.

First, there is a single Event Bus (and it is shared between Vert.x instances when Vert.x is started in cluster mode). Its role is to allow a message passing style of communication between your verticles.

请参见事件总线部分.

然后在Vert.x中有不同类型的线程:事件循环线程和辅助线程.默认情况下,Vert.x创建的事件循环线程与计算机上的内核一样多,并包含20个工作线程.事件循环线程用于处理异步事件(已读取文件缓冲区,已接收消息等).辅助线程用于执行应用程序的阻塞部分.

Then there are different types of threads in Vert.x: event loop threads and worker threads. By default, Vert.x creates as many event loop threads as cores on the machine, and a pool of 20 worker threads. Event loop threads are used to handle asynchronous events (file buffer was read, message has been received,... etc). Worker threads are used to execute the blocking parts of your application.

请参见多反应器模式一个顶点是部署的Vert.x单元.共有三种类型的顶点,但是您应该知道的两种是标准"顶点和工人"顶点.部署标准顶点时,会为其分配单个事件循环线程.您在顶点中处理的任何类型的事件都将由此单个事件循环线程处理.保证工作线程顶点一次由单个工作线程执行.每次可能不是同一工作线程,但是永远不会有两个工作线程并行处理工作线程事件.

A verticle is the Vert.x unit of deployment. There are three types of verticles but the two you should know are "standard" verticles and "worker" verticles. Standard verticles are assigned a single event loop thread when they are deployed. Whichever type event you handle in your verticle will be handled by this single event loop thread. Worker verticles are guaranteed to be executed by a single worker thread at a time. It may not be the same worker thread each time, but never two worker threads will handle worker verticle events in parallel.

请参见顶点

最终,要扩展Vert.x应用程序,请部署多个顶点实例.对于标准verticle,每个实例将分配一个不同的事件循环,以便您扩展内核.

Eventually, to scale a Vert.x application, you deploy multiple instances of your verticles. For standard verticles, each instance will get a different event loop assigned so you will scale across your cores.

请参见顶点实例数

Vert.x不会自动为您调整Verticles的数量.不过,您可以使用Vert.x监视工具来构建.

Vert.x doesn't automatically adjust the number of Verticles for you. This is something you could build with Vert.x monitoring tools though.

我相信这能回答您的三个问题.

I belive this answers your three questions.

这篇关于Vertx扩展每个线程的实例数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆