Vertx.vertx()初始框图和模块
Vertx.vertx()实例
一、构造方法
1. VertxImpl构造方法 选择 transports protocol , default select 模型
- if (options.getPreferNativeTransport()) {
- Transport nativeTransport = Transport.nativeTransport();
- if (nativeTransport != null && nativeTransport.isAvailable()) {
- transport = nativeTransport;// 使用netty-transport-native epoll-ET 或 Kqueue
- } else {
- transport = Transport.JDK;// java.nio (linux下 epoll-LT)
- }
- } else {
- transport = Transport.JDK;// java.nio (linux下 epoll-LT)
- }
native transports protocol
transports | TCP | UDP | SCTP | UDT |
---|---|---|---|---|
jdk-NIO | X | X | X | X |
netty-native-epoll | X | X | — | — |
OIO | X | X | X | X |
- PS : select 模型是线性扫描所有 FD , 时间复杂度O(n), 轮训机制.
- epoll 模型基于callback机制 , k 活跃数 时间复杂度O(k).
- 试用场景: 大量FD 基本都是活跃状态,select 比 epoll 优秀,没有epollctl的回調开销,
- 反之有大量idle , dead状态 , epoll更优秀
2. BlockedThreadChecker线程,检查所有线程阻塞, 观察者模式
- //默认Timer每 1 seconds检查一次 , 默认warn时间 5 seconds
- checker = new BlockedThreadChecker(options.getBlockedThreadCheckInterval()
- , options.getWarningExceptionTime());
- //守护线程,监听所有阻塞线程,遍历扫描(container) WeakHashMap 弱引用,
- //ContextImpl.runCloseHooks 执行结束置为null,使GC线程自动回收资源, 防止内存泄漏
- timer = new Timer("vertx-blocked-thread-checker", true);
- timer.schedule(...);
3. eventloop线程池
- eventloop线程本质是对netty eventloop的封装.
- eventLoopGroup = transport.eventLoopGroup(options.getEventLoopPoolSize()
- ,eventLoopThreadFactory, NETTY_IO_RATIO);
- // 默认 2 * number of cores ,linux下依赖 /proc/self/status 做计算
- acceptorEventLoopGroup = transport.eventLoopGroup(
- , acceptorEventLoopThreadFactory, );
- //负责客户端连接,线程1,单进程服务线程为1即可,否则造成资源浪费
- note: eventloop线程checker默认最大阻塞时间 2 seconds,处理时间越长,eventloop事件堆积 就越多,影响服务正常响应,切不可阻塞,阻塞任务可换成worker线程池运行
4. worker线程池
worker线程池是J.U.C包下的FixedThreadPool,默认default 20
- ExecutorService workerExec=Executors.newFixedThreadPool(
- options.getWorkerPoolSize(),new VertxThreadFactory("vert.x-worker-thread-"
- ,checker, true, options.getMaxWorkerExecuteTime()));
note: worker主要用来处理耗时任务, 阻塞同步的调用而设计,checker默认超时时间 60 seconds, 执行行为两种, 串行(采用数据结构队列,FIFO) ; 并行 .
5.internal 线程池
internal线程池是J.U.C包下的FixedThreadPool,默认default 20
- ExecutorService internalBlockingExec = Executors.newFixedThreadPool(
- options.getInternalBlockingPoolSize()
- ,new VertxThreadFactory("vert.x-internal-blocking-"
- ,checker, true, options.getMaxWorkerExecuteTime()));
note: 内部使用的线程池,主要用来将阻塞代码异步化
5.初始化加载模块
- //创建文件解析器,会创建一个 cache 目录,默认当前执行目录建立隐藏文件夹.vertx,
- //使用 kill -15 <pid> 使进程触发ShutdownHook清理 cache目录文件和目录
- fileResolver = new FileResolver(this, options.isFileResolverCachingEnabled());
- /**
- * 创建地址解析器,会读取/etc/resolv.conf DNS配置文件,
- * resolv.conf手册地址:http://www.man7.org/linux/man-pages/man5/resolv.conf.5.html
- */
- addressResolver = new AddressResolver(this, options.getAddressResolverOptions());
- //创建部署Verticle管理器
- deploymentManager = new DeploymentManager(this);
- //启用集群cluster,创建集群管理器
- clusterManager = getClusterManager(options);
- //集群状态下创建HA管理器(高可用)
- haManager = new HAManager(this, deploymentManager, clusterManager, options.getQuorumSize(), options.getHAGroup(), haEnabled);
- //创建并且启动事件总线,local和cluster模式实现不同
- createAndStartEventBus(options, resultHandler);
- //创建sharedData实例,共享数据,local和cluster模式实现不同
- sharedData = new SharedDataImpl(this, clusterManager);
- //创建抽象层的文件系统模块,AsyncFileImpl 依赖 java nio AsynchronousFileChannel
- // private final FileSystem fileSystem = getFileSystem();
- //不同操作系统call调用有兼容问题,最好开发环境和发布环境一致
- Utils.isWindows() ? new WindowsFileSystem(this) : new FileSystemImpl(this)
- //初始化度量指标
- metrics = initialiseMetrics(options);
5. static 块
- static {
- // 关闭netty的资源泄露器检查,有性能的一定开销
- ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
- // 默认使用 Jdk deflater/inflater
- System.setProperty("io.netty.noJdkZlibDecoder", "false");
- }
二、其它模块
- //创建DNSclient
- DnsResolverProvider provider = new
- DnsResolverProvider(this,addressResolverOptions);
- //创建异步的httpClient,协议包括 HTTP_1_0 , HTTP_1_1 , HTTP_2 和 HTTPS
- new HttpClientImpl(this, options);
- //创建httpServer, 默认协议协商版本 HTTP/2 , HTTP/1.1 , 支持 https
- //(SNI:多证书单服务需要集成KeyCertOptions自己实现)
- new HttpServerImpl(this, serverOptions);
- //创建tcp服务端,支持 tls
- new NetServerImpl(this, options);
- //创建tcp客户端,支持 tls
- new NetClientImpl(this, options);
- //创建udp服务
- DatagramSocketImpl.create(this, options);
- //额外 CLI(command-line interface) , cli 模块
框图
REQUIRED MODEL
FREE MODEL
整体框图
Vertx.vertx()初始框图和模块的更多相关文章
- vertx实例的fileSystem文件系统模块
初始化 //根据OS区分实现 System.getProperty("os.name").toLowerCase(); Utils.isWindows() ? new Window ...
- vertx模块HAManager高可用
HAManager public HAManager(VertxInternal vertx, DeploymentManager deploymentManager, ClusterManager ...
- vertx模块DeploymentManager部署管理器
DeploymentManager public DeploymentManager(VertxInternal vertx) { this.vertx = vertx; loadVerticleFa ...
- vertx.io 与nodejs 一个简单的性能比较
vertx.io 与node 都是可以进行js运行的一个引擎,但是vertx 支持的语言相对于node 多,可以查看官网.今天下网上查询相关的信息 时来了解到vertx.io 性能比node 好,于是 ...
- vertx核心类之VertxImpl
在Vert.x中,Vertx接口是最为重要的一个接口,vertx-core的基础功能都在此接口中提供.这篇文章中我们就来分析一下Vertx接口体系的内部实现以及创建流程.本文对应Vert.x的版本为 ...
- vertx简单客户端创建
import java.util.HashMap;import java.util.Map; import com.yunva.vertx.test.vertproject.util.JsonUtil ...
- vertx简单服务创建
import java.util.HashMap;import java.util.Map; import org.slf4j.Logger;import org.slf4j.LoggerFactor ...
- Kotlin & Vertx 构建web服务
感想 Kotlin 是一门好语言,值得大家了解一下. Vertx 是一个好框架,也值得大家了解一下. Kotlin 写过js,也写过一点点go,主力一直是java.用了kotlin,貌似找到了常用语言 ...
- Kotlin Vertx
Kotlin & Vertx Kotlin 是一门好语言,值得大家了解一下. Vertx 是一个好框架,也值得大家了解一下. Kotlin 写过js,也写过一点点go,主力一直是java.用了 ...
随机推荐
- poj-2195(最小费用流)
题意:给你一个n*m的地图,H代表这个点有一个房子,m代表这个点是一个人,每次h走一步就花费一,问最小花费使得每个人能进入一个房间 代码:建立一个源点和汇点,每个人和源点相连,每个房子和汇点相连,每个 ...
- VueRouter和Vue生命周期(钩子函数)
一.vue-router路由 1.介绍 vue-router是Vue的路由系统,用于定位资源的,在页面不刷新的情况下切换页面内容.类似于a标签,实际上在页面上展示出来的也是a标签,是锚点.router ...
- C. Multiplicity 简单数论+dp(dp[i][j]=dp[i-1][j-1]+dp[i-1][j] 前面序列要满足才能构成后面序列)+sort
题意:给出n 个数 的序列 问 从n个数删去任意个数 删去的数后的序列b1 b2 b3 ......bk k|bk 思路: 这种题目都有一个特性 就是取到bk 的时候 需要前面有个bk-1的序列前 ...
- Magento2自定义命令
命令命名准则 命名指南概述 Magento 2引入了一个新的命令行界面(CLI),使组件开发人员能够插入模块提供的命令. Command name Command name 在命令中,它紧跟在命令的名 ...
- 【并发编程】一个最简单的Java程序有多少线程?
一个最简单的Java程序有多少线程? 通过下面程序可以计算出当前程序的线程总数. import java.lang.management.ManagementFactory; import java. ...
- Python爬虫之二
1)什么叫做URL url是统一资源定位符,对可以从互联网上得到的资源的位置和访问方法的一种简洁的表示,是互联网上标准资源的地址.互联网上的每个文件都有一个唯一的URL,它包含的信息指出文件的位置以及 ...
- 越光后端开发——ygapi(2.新建Model)
1.新建Model 1.users数据 1.在apps/users/models.py中: from datetime import datetime from django.db import mo ...
- redis的list取出数据方式速度测试
redis测试: package business; import java.io.BufferedReader; import java.io.File; import java.io.FileIn ...
- Ubuntu16.04 安装g++6
https://blog.csdn.net/qq_34877350/article/details/81182022 1.安装gcc-6: sudo apt-get update && ...
- 2018年秋季学期《c语言程序设计》助教总结
<c语言程序设计>第七周助教总结 <c语言程序设计>第八周助教总结 <c语言程序设计>第九周助教总结 <c语言程序设计>第十周助教总结 <c语言程 ...