美文网首页
切片服务中对node的折腾

切片服务中对node的折腾

作者: AcceptedLc | 来源:发表于2018-10-10 10:58 被阅读44次

1 通过控制nodejs线程池大小,控制cpu资源的占用

环境:16核32g

node的线程池

第一类:v8的线程,通过--v8-pool-size=num 设置

Set V8's thread pool size which will be used to allocate background jobs.
  If set to `0` then V8 will choose an appropriate size of the thread pool based on the number of online processors.
  If the value provided is larger than V8's maximum, then the largest value will be chosen.

第二类:libuv的线程,UV_THREADPOOL_SIZE=size

Set the number of threads used in libuv's threadpool to `size` threads.

Asynchronous system APIs are used by Node.js whenever possible, but where they do not exist, libuv's threadpool is used to create asynchronous node APIs based on synchronous system APIs. Node.js APIs that use the threadpool are:

*   all `fs` APIs, other than the file watcher APIs and those that are explicitly synchronous
*   `crypto.pbkdf2()`
*   `crypto.randomBytes()`, unless it is used without a callback
*   `crypto.randomFill()`
*   `dns.lookup()`
*   all `zlib` APIs, other than those that are explicitly synchronous

Because libuv's threadpool has a fixed size, it means that if for whatever reason any of these APIs takes a long time, other (seemingly unrelated) APIs that run in libuv's threadpool will experience degraded performance. In order to mitigate this issue, one potential solution is to increase the size of libuv's threadpool by setting the `'UV_THREADPOOL_SIZE'` environment variable to a value greater than `4` (its current default value). For more information, see the [libuv threadpool documentation](http://docs.libuv.org/en/latest/threadpool.html).

不加参数启动node进程

进程启动 承载压力的时候

对比刚启动的时候,libuv的线程池扩容了4个

将libuv进程池大小设置为20个

刚启动 增加负载

对比发现,上面有21个进程处于Rsl,20个是libuv线程池的,1个是v8自己的线程池

总结:

  • 在nodejs 中如果使用libuv的uv_thread做耗时运算,则需要调整libuv的线程池
    • 如果默认设置过大,很容易造成cpu过载(这次的问题)
    • 如果默认设置过小,会浪费cpu资源
    • 如果js工程比较小,调小v8线程池
  • 对于普通js工程,可以尝试调节v8线程池数量,提高js执行速度

ps Stat 列注解

 S    Interruptible sleep (waiting for an event to complete)
 s    is a session leader
 l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
 R    running or runnable (on run queue)

相关文章

  • 切片服务中对node的折腾

    1 通过控制nodejs线程池大小,控制cpu资源的占用 环境:16核32g node的线程池 第一类:v8的线程...

  • HTTP模块

    Node的HTTP模块包含对http处理的封装。在node中,HTTP服务继承自TCP服务器(net模块),它能够...

  • node 视频服务器 切片ffmpeg

    node 视频服务器 切片ffmpeg 第一部分 音视频相关概念 1.1 视频相关概念 1.1.1 分辨率 分辨率...

  • ArcGIS 切片服务无法访问到切片,Server Manage

    一、报错内容 从切片服务器拷贝的切片包,在本地ArcGIS Server启动服务后无法加载切片,切片图标为灰色。 ...

  • arcgis for javascript(4.12)加载切片服

    怎样加载arcgis 切片服务,加载切片服务使用的是"esri/layers/TileLayer"接口 填写好服务...

  • 一个前端的nginx之旅

    前段时间买了个服务器和域名,开始折腾服务器。安装了node和nginx作为服务器容器,对于nginx的使用有了基本...

  • node中间层

    基本流程:客户端请求node服务器,node服务分析请求(此步可也可根据情况,从node层的缓存中取数据),再请求...

  • 2019-04-26 nvm、node、npm、nrm、yarn

    前言 nvm、node、npm的关系nvm: 一个命令行工具,主要用于对Node版本的管理node: 运行在服务端...

  • go 语言切片

    go 语言切片 简单切片 slice 是 对 array 的一个 view 创建简单切片 切片作为函数参数 对切...

  • Openlayers调用GeoServer发布的WMTS地图服务

    OpenLayers中提供了调用WMTS服务的接口。其主要思想是先构建切片信息,再传入服务信息即可。切片信息包括切...

网友评论

      本文标题:切片服务中对node的折腾

      本文链接:https://www.haomeiwen.com/subject/eiyyaftx.html