GithubHelp home page GithubHelp logo

cap 和 running 比较的问题 about ants HOT 5 CLOSED

panjf2000 avatar panjf2000 commented on August 28, 2024
cap 和 running 比较的问题

from ants.

Comments (5)

naiba avatar naiba commented on August 28, 2024

加锁后资源消耗会增加,性能会下降很多,所以是加锁确保池数量还是不加锁保证性能呢?

from ants.

panjf2000 avatar panjf2000 commented on August 28, 2024

并发量不大的情况下还是建议直接用goroutine,不然池化未必比裸用goroutine性能好,甚至会下降。

from ants.

naiba avatar naiba commented on August 28, 2024

from ants.

panjf2000 avatar panjf2000 commented on August 28, 2024

那个compare操作的确不是原子操作,一种潜在的可能是:在比较过程中,某个worker结束任务了,把running数减一了,这可能导致pool有轻微的goroutine数量溢出。但是,

第一,发生的概率很小而且也只会是轻微溢出,我觉得在容忍限度以内;

第二, 如果要完全保证数据强正确的话,得再加锁,但这样不仅会让代码更加复杂,而且性能也会有比较大的下降,我觉得有点舍本逐末了。

目前我没想到既能保证性能又能保证数值绝对正确的实现方法,这个我后续有空再思考下,要是你有好的方法的话也欢迎提个PR我们一起讨论下😀,我先把issue设置成enhancement,以后慢慢优化。

from ants.

naiba avatar naiba commented on August 28, 2024

from ants.

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.