1 Star 1 Fork 0

Serverless Devs Registry / keep-warm-fc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Keep-warm-fc Plugin

image

node.js version license

本插件帮助您通过 Serverless-Devs 工具和 FC组件 实现实例预热,降低冷启动的概率。

快速开始

作用

本插件主要通过定时触发器预热函数达到有效降低冷启动的概率目的

快速上手

website-fc本质是针对FC组件进行增强。 还是遵循FC组件的Yaml规范

通过s init start-keep-warm-fc 快速体验keep-warm-fc插件

在执行部署钩子post-deploy之后声明插件, 同时声明Http函数的访问链接

actions:
  post-deploy: # 在deploy之后运行
    - plugin: keep-warm-fc
      args:
        url: ${otherService.output.url.system_url}

参数说明

参数名称 默认值 参数含义 必填
url - Http函数的访问地址 true
method head Timer请求方法 false
cronExpression 2m 请求的频率(默认2分钟) false
enable true 定时函数是否开启 false

特别提醒:默认的请求methodhead生效的前提是trigger以及domain支持head方法。配置如下:

triggers:
  - name: httpTrigger
    type: http
    config:
      authType: anonymous
      methods:
        - GET
        - HEAD # 这里需要支持HEAD方法,Timer触发器使用
customDomains:
  - domainName: auto
    protocol: HTTP
    routeConfigs:
      - path: /*
        methods:
          - GET
          - HEAD # 这里需要支持HEAD方法,Timer触发器使用

注意事项

  1. 如果您需要关闭定时触发器,可以设置参数 enable: false, 或者删除定时函数
  2. 如果您需要定时触发器生效,最佳实践是将triggermethod方法,添加上HEAD类型。这样的话,性能是相对最好的

工作原理

工作原理比较简单,就是在完成当前部署后。post-deploy的钩子函数中,部署一个定时触发器的辅助函数,函数名格式为_FC_PLUGIN_keep-warm-${serviceName}-${functionName},这个函数每隔2m(默认是2分钟,用户可以通过cronExpression参数配置)会触发一次主函数(Http函数)中的URL,达到降低冷启动概率的目的。

实现代码

def handler(event, context):
  url = os.environ['KEEP_WARM_FC_URL']
  res = requests.head(url)
  return res.status_code

关于我们

MIT License Copyright (c) 2020 Serverless Devs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

fc warm插件,减少函数计算冷启动,保持温状态 展开 收起
JavaScript 等 3 种语言
MIT
取消

发行版 (4)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/devsapp/keep-warm-fc.git
git@gitee.com:devsapp/keep-warm-fc.git
devsapp
keep-warm-fc
keep-warm-fc
master

搜索帮助