SAP Spartacus 服务器端渲染的三种可能情形

举报
Jerry Wang 发表于 2022/07/20 12:38:51 2022/07/20
【摘要】 执行到代码 166 行,将控制逻辑交给 expressEngine 之后,点 F8 后,下列三种不同颜色的代码块可能会被调用到:绿色代码块说明 timeout 指定的时间间隔到了。timeout:Time in milliseconds to wait for SSR rendering to happen, 等待 SSR 渲染开始的超时时间,而不是 SSR 渲染的 duration.黄色代...

执行到代码 166 行,将控制逻辑交给 expressEngine 之后,点 F8 后,下列三种不同颜色的代码块可能会被调用到:

  1. 绿色代码块

说明 timeout 指定的时间间隔到了。timeout:Time in milliseconds to wait for SSR rendering to happen, 等待 SSR 渲染开始的超时时间,而不是 SSR 渲染的 duration.

  1. 黄色代码块

SSR 执行时间太长了,还没有完成。如果超过 maxRenderTime,会强行释放 concurrency slot, 允许新的请求被 SSR 响应。但是,对于超时的 SSR 服务请求,申请的资源并未释放,可能会导致内存泄漏。默认时间为 5 分钟。

  1. 红色代码块

如果执行到这里,并且 maxRenderTimeout 不为 undefined,说明是正常的 SSR 渲染请求执行成功的情形。

timeout

Time in milliseconds to wait for SSR rendering to happen.

It does not mean the actual duration spent by a SSR rendering request, but the range between the timestamp when SSR receives a render request and that request actually gets processed by SSR server.

等待 SSR 渲染发生的时间(以毫秒为单位)。

它并不意味着 SSR 渲染请求所花费的实际持续时间,而是 SSR 收到渲染请求时的时间戳与该请求实际被 SSR 服务器处理之间的范围。

forcedSsrTimeout

Time in milliseconds to wait for rendering when SSR_ALWAYS render strategy is set for the request.

Default value is 60 seconds.

in file optimized-ssr-engine.ts, we set a timer with timeout value specified by line 130, this.getTimeout function call:

为请求设置 SSR_ALWAYS 渲染策略时等待渲染的时间(以毫秒为单位)。

默认值为 60 秒。

在文件优化 ssr-engine.ts 中,我们设置了一个定时器,其超时值由第 130 行指定,this.getTimeout 函数调用:

The logic of final timeout value is determined as below:

  1. if request rendering strategy is specifed explicitly by customers to ALWAYS_SSR, then the timeout is coming from forcedSsrTimeout option. If customers specify ALWAYS_SSR but forget to fill forcedSsrTimeout, then 60 seconds is used as default value.

  2. In most cases customers will use RenderingStrategy.DEFAULT as default strategy. In this case, timeout value comes from option timeout.

In other words, forcedSsrTimeout only takes effect, if customer uses RenderingStrategy.ALWAYS_SSR.

  1. 如果客户明确指定了请求渲染策略到 ALWAYS_SSR,那么超时来自于forcedSsrTimeout 选项。 如果客户指定ALWAYS_SSR但忘记填写forcedSsrTimeout,则使用60秒作为默认值。

  2. 在大多数情况下,客户会使用 RenderingStrategy.DEFAULT 作为默认策略。 在这种情况下,超时值来自选项超时。

换句话说,只有在客户使用 RenderingStrategy.ALWAYS_SSR 时,forcedSsrTimeout 才会生效。

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。