了解CRO请求/响应周期和内存使用
我对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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CRO请求处理管道是
供应
块的链条,并通过请求并通过响应通过。关于要创建的最佳处理线程数量的决定保留到Rakuthreadpoolscheduler
实现。就连接寿命而言,这取决于客户端(即Web浏览器)的关闭方式;如果浏览器使用保留的HTTP/1.1连接或保留HTTP/2.0连接,请尊重该请求。
关于记忆使用,增长到一定程度不足为奇。如果最终没有升级,这只是一个问题。原因包括:
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 RakuThreadPoolScheduler
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: