Giter VIP home page Giter VIP logo

Comments (4)

matyhtf avatar matyhtf commented on August 17, 2024

异步 Server 在执行完 onMessage 回调之后协程就会退出,而 Coroutine Server 不同,同一个客户端连接总会有一个协程,因此 250 个客户端就会有 250 协程,需要占用内存。

from swoole-src.

xuanyanwow avatar xuanyanwow commented on August 17, 2024

异步 Server 在执行完 onMessage 回调之后协程就会退出,而 Coroutine Server 不同,同一个客户端连接总会有一个协程,因此 250 个客户端就会有 250 协程,需要占用内存。

250个协程不至于造成3倍的资源消耗吧

from swoole-src.

matyhtf avatar matyhtf commented on August 17, 2024

3倍只是巧合

from swoole-src.

xuanyanwow avatar xuanyanwow commented on August 17, 2024

并不是纠结于这个“3”,而是对于其中的消耗点想要更详细的了解

run(function () {
    $i = 250;
    while ($i--) {
        Coroutine::create(function () {
            while (true) {
                sleep(1);
            }
        });
    }

    // 内存使用
    $memory = memory_get_usage();
    $memory = $memory / 1024;
    $memory = $memory / 1024;
    $memory = round($memory, 2);
    echo '当前内存使用:' . $memory . 'MB' . PHP_EOL;

    $channel = new Channel(1);
    $channel->pop();
});

当前内存使用:3.84MB

而上面的实验结果差异为:54-18=36MB,不止协程占用的内存消耗

from swoole-src.

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.