了解CRO请求/响应周期和内存使用

发布于 2025-01-28 01:26:16 字数 986 浏览 1 评论 0原文

我对CRO如何处理客户端请求有些困惑,具体来说,为什么某些请求似乎会导致CRO的记忆使用。

一个最小的例子显示在“ noreferrer”>“ noreferrer”>字面的“ hello hello world!” CRO服务器

use Cro::HTTP::Router;
use Cro::HTTP::Server;

my $application = route {
    get -> {
        content 'text/html', 'Hello Cro!';
    }
}

my Cro::Service $service = Cro::HTTP::Server.new:
    :host<localhost>, :port<10000>, :$application;

$service.start;

react whenever signal(SIGINT) {
    $service.stop;
    exit;
}

该服务器所做的一切都是响应以获取“ Hello Cro!”的请求。 - 但是,如果我导航到Localhost:10000,然后迅速刷新页面,我会注意到CRO的内存使用开始攀登(然后

仅 保持升级)当刷新是 appain 时,似乎会发生,这表明该问题可能与未正确关闭连接或与并发问题有关(也许与可能与之相关的

/stackoverflow.com/questions/69421730/- the-pointing-thepointing-the-point-supply-blocks-on-demand-supplies"> prior 为简单起见,服务器省略了吗?

I'm a bit confused about how Cro handles client requests and, specifically, why some requests seem to cause Cro's memory usage to balloon.

A minimal example of this shows up in the literal "Hello world!" Cro server.

use Cro::HTTP::Router;
use Cro::HTTP::Server;

my $application = route {
    get -> {
        content 'text/html', 'Hello Cro!';
    }
}

my Cro::Service $service = Cro::HTTP::Server.new:
    :host<localhost>, :port<10000>, :$application;

$service.start;

react whenever signal(SIGINT) {
    $service.stop;
    exit;
}

All that this server does is respond to GET requests with "Hello Cro!' – which certainly shouldn't be taxing. However, if I navigate to localhost:10000 and then rapidly refresh the page, I notice Cro's memory use start to climb (and then to stay elevated).

This only seems to happen when the refreshes are rapid, which suggests that the issue might be related either to not properly closing connections or to a concurrency issue (a maybe-slightly-related prior question).

Is there some performance technique or best practice that this "Hello world" server has omitted for simplicity? Or am I missing something else about how Cro is designed to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二货你真萌 2025-02-04 01:26:16

CRO请求处理管道是供应块的链条,并通过请求并通过响应通过。关于要创建的最佳处理线程数量的决定保留到Raku threadpoolscheduler实现。

就连接寿命而言,这取决于客户端(即Web浏览器)的关闭方式;如果浏览器使用保留的HTTP/1.1连接或保留HTTP/2.0连接,请尊重该请求。

关于记忆使用,增长到一定程度不足为奇。如果最终没有升级,这只是一个问题。原因包括:

  • 确定需要更多线程的调度程序来处理负载。每个操作系统线程都带有VM内部的一些顶部,其中大多数是GC苗圃是每个线程的,以允许简单的颠簸分配。
  • 使用内存的MOARVM优化器用于专门字体模板和JIT编译的机器代码,该代码在应用程序运行时在后台产生,并且由某些代码驱动,并执行了足够的时间。
  • GC试图收集完整的收集阈值。

The Cro request processing pipeline is a chain of supply blocks that requests and, later, responses pass through. Decisions about the optimal number of processing threads to create are left to the Raku ThreadPoolScheduler implementation.

So far as connection lifetime goes, it's up to the client - that is, the web browser - as to how eagerly connections are closed; if the browser uses a keep-alive HTTP/1.1 connection or retains a HTTP/2.0 connection, Cro respects that request.

Regarding memory use, growth up to a certain point isn't surprising; it's only a problem if it doesn't eventually level out. Causes include:

  • The scheduler determining more threads are required to handle the load. Each OS thread comes with some overhead inside the VM, the majority of it being that the GC nursery is per thread to allow simple bump-the-pointer allocation.
  • The MoarVM optimizer using memory for specialized bytecode and JIT-compiled machine code, which it produces in the background as the application runs, and is driven by certain bits of code having been executed enough times.
  • The GC trying to converge on a full collection threshold.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文