GithubHelp home page GithubHelp logo

nginx平台初探(30%)¶ ngx_accept_disabled = ngx_cycle->connection_n / 8 - ngx_cycle->free_connection_n;if (ngx... about nginx-book HOT 4 CLOSED

taobao avatar taobao commented on June 16, 2024
nginx平台初探(30%)¶ ngx_accept_disabled = ngx_cycle->connection_n / 8 - ngx_cycle->free_connection_n;if (ngx...

from nginx-book.

Comments (4)

jinglong avatar jinglong commented on June 16, 2024

这位同学你好,你这里的最后2句话说的有些偏差,nginx中使用accept mutex锁的目的是为了解决“惊群”问题,所谓“惊群”是指如果多个进程同时监听一个套接字时,并同时在epoll上注册,当该套接字上的一个连接过来时,epoll会同时唤醒所有的进程,这时所有进程醒来都去accept该连接,实际只能有一个进程accept成功,也就是accept失败的进程实际上是白白浪费了cpu,而且此时多进程之间的请求处理的均衡性依赖于系统本身。 nginx采用了一把锁来解决此问题,当然也采用了简单的算法来调度新连接在多进程之间的分发,但并不是说一个进程在处理新请求时,其他进程就一定在休息了,它可能还在忙于处理之前的请求,均衡算法的目标保证了每个cpu都有事做,并且尽可能的公平(保证每个进程都有差不多的工作量)

from nginx-book.

wangwei1237 avatar wangwei1237 commented on June 16, 2024

嗯,原来是这样的。看来在最后两句话上我的理解有偏差。听君一席话,醍醐灌顶,多谢大神的指点。还是希望大神把这里的workerngx_accept_disable--讲解一下。期待ing.

from nginx-book.

jinglong avatar jinglong commented on June 16, 2024

你好,非常抱歉实际文章中贴的代码有点问题,
(1) ngx_accept_disabled = ngx_cycle->connection_n / 8
- ngx_cycle->free_connection_n;

(2) if (ngx_accept_disabled > 0) {
ngx_accept_disabled--;

}
这2段实际应该分开,不应该放在一块,放在一块会让人误解,这里我们会改一下。 代码段(1)的实际位置在ngx_event_accept()函数中,代码段(2)在ngx_process_events_and_timers()函数中。ngx_accept_disabled变量是均衡算法的一部分,用来控制进程是否去抢accept锁,基本**就是进程当前空余连接数越少(ngx_accept_disabled则越大),就越要放弃抢锁的机会,同时ngx_accept_disabled--的目的是保证进程在某个时刻总是有机会去抢一下,文章中有过介绍了。

from nginx-book.

jinglong avatar jinglong commented on June 16, 2024

先打开吧,改了那代码再关闭

from nginx-book.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.