fevin / Gracehttp
graceful http server for golang. (平滑重启)
Stars: ✭ 54
Labels
Projects that are alternatives of or similar to Gracehttp
Goloader
load and run golang code at runtime. (WARNING: this repo has not been maintained for a long time, please take a look at https://github.com/pkujhd/goloader)
Stars: ✭ 564 (+944.44%)
Mutual labels: hot-reload
Got Reload
Reload Go code in a running process at function/method level granularity, using Yaegi
Stars: ✭ 29 (-46.3%)
Mutual labels: hot-reload
Cp Ddd Framework
A lightweight flexible development framework for complex business architecture with full ecosystem!轻量级业务中台开发框架,中台架构的顶层设计和完整解决方案!
Stars: ✭ 566 (+948.15%)
Mutual labels: hot-reload
Svelte Redux Shopping Cart
Example Shopping Cart App using Svelte, Redux, and Webpack
Stars: ✭ 13 (-75.93%)
Mutual labels: hot-reload
Vue Loader
📦 Webpack loader for Vue.js components
Stars: ✭ 4,778 (+8748.15%)
Mutual labels: hot-reload
Deku
⛄️ No-bundle Dev Server for ES modules with deno.
Stars: ✭ 43 (-20.37%)
Mutual labels: hot-reload
Proxy Hot Reload
Node.js application hot reload with `Proxy`.
Stars: ✭ 19 (-64.81%)
Mutual labels: hot-reload
Hr4r
Example project - "Hot Reloading 4 RequireJS" front-end web applications & some extra code demonstrating hot-reloading for Node.js Express servers
Stars: ✭ 28 (-48.15%)
Mutual labels: hot-reload
Nth Start Project
Startkit for HTML / CSS / JS pages layout.
Stars: ✭ 578 (+970.37%)
Mutual labels: hot-reload
Webpack Dev Server
Serves a webpack app. Updates the browser on changes. Documentation https://webpack.js.org/configuration/dev-server/.
Stars: ✭ 7,250 (+13325.93%)
Mutual labels: hot-reload
Jengine
JEngine是针对Unity开发者设计的开箱即用的框架,封装了强大的功能,小白也能快速上手,轻松制作可以热更新的游戏 | JEngine is a streamlined and easy-to-use framework designed for Unity Programmers which contains powerful features, beginners can start up quickly and making hot update-able games easily
Stars: ✭ 564 (+944.44%)
Mutual labels: hot-reload
Hot Reload.vim
A (Neo)vim plugin for Flutter to automatically hot reload the project every time a file is saved
Stars: ✭ 33 (-38.89%)
Mutual labels: hot-reload
Boot Figreload
Boot task providing live-reload using Fighweel client
Stars: ✭ 50 (-7.41%)
Mutual labels: hot-reload
React Pwa Webpack Starter
Boilerplate to build a React PWA with Webpack + Workbox
Stars: ✭ 38 (-29.63%)
Mutual labels: hot-reload
gracehttp
优雅的使用 HTTP Server
环境
- Go 1.14+
支持功能
- 平滑重启(
Zero-Downtime
); - 平滑关闭;
- 多
Server
添加(包含HTTP
、HTTPS
); - 自定义日志组件;
- 支持单个端口 server 链接数限流,默认值为:C100K。超过该限制之后,请求阻塞,并且不会消耗文件句柄,避免发生雪崩,压坏服务。
使用此 pkg 会给你带来什么
- 平滑升级服务,不影响用户体验;
- 方便的多
server
添加; - 对
server
进行过载保护,通过设置合适的阀值,避免too many open files
错误;
使用指南
go get github.com/fevin/gracehttp
添加服务
@see main_test/gracehttp_main.go
退出或者重启服务
- 重启:
kill -HUP pid
或kill -HUP pid
- 退出:
kill -QUIT pid
添加自定义日志组件
gracehttp.SetErrorLogCallback(logger.LogConfigLoadError)
此处提供了三个 Set*
方法,分别对应不同的日志等级:
- SetInfoLogCallback
- SetNoticeLogCallback
- SetErrorLogCallback
关于链接数限制
参考实现:golang/net/netutil 实现原理:
- 通过
channel-buffer
来控制并发量:每个请求都会获取一个缓冲单元,直到缓冲区满; - 只有获取
buffer
的请求才能进行accept
; - 如果缓冲区满了,后来的请求会阻塞,直到
conn.close
或者 缓冲区有空闲
测试
HTTP Server 常规测试
✗ go test -v github.com/fevin/gracehttp
=== RUN TestHTTPServer
--- PASS: TestHTTPServer (0.00s)
gracehttp_test.go:106: ******* test multi server *******
gracehttp_test.go:77: [test http server 1]
gracehttp_test.go:87: http server 1 success, response: pong by pid:5385
gracehttp_test.go:92: [test http server 2]
gracehttp_test.go:102: http server 2 success, response: pong by pid:5385
PASS
ok github.com/fevin/gracehttp 0.016s
平滑重启功能测试
// 以下操作需要开启 go mod
✗ git clone https://github.com/fevin/gracehttp.git
✗ go build main_test/gracehttp_main.go
✗ nohup ./gracehttp_main 2>&1 > gracehttp.log &
✗ curl http://localhost:9090/ping
pong by pid:86703
✗ kill -USR1 86703
[1] + 86703 done nohup ./bin/gracehttp_main 2>&1 > gracehttp.log
✗ cat gracehttp.log
2019/12/20 12:07:38 [gracehtto-log][Info] [Received SIG. [PID:86703, SIG:user defined signal 1]]
2019/12/20 12:07:38 [gracehtto-log][Info] [start new process success, pid 86818.]
# 再次执行 curl,发现 pid 已经变化
✗ curl http://localhost:9090/ping
pong by pid:86818
✗ kill -QUIT 86818
✗ cat gracehttp.log
2019/12/20 12:07:38 [gracehtto-log][Info] [Received SIG. [PID:86703, SIG:user defined signal 1]]
2019/12/20 12:07:38 [gracehtto-log][Info] [start new process success, pid 86818.]
2019/12/20 12:08:56 [gracehtto-log][Info] [Received SIG. [PID:86818, SIG:quit]]
@see test ./gracehttp_test.go.
@see demo ./main_test/gracehttp_main.go
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].