2026年4月6日

[AI生成] github smux源码分析

摘要: https://github.com/xtaci/smux 特点 smux = 在一条 TCP 连接里,同时跑多条虚拟 “数据流”普通 TCP:一条连接 = 一条路,只能发一股数据smux 多路复用:一条连接 = 一条高速公路,里面划分多条车道,同时跑多组数据互不干扰作用:省连接、省资源、更快、更稳 阅读全文

posted @ 2026-04-06 14:46 王景迁 阅读(4) 评论(0) 推荐(0)

[AI生成] 基于smux实现在单条TCP连接上收发http

摘要: 工作流程 Client -->|1. 建立 TCP 连接| Server Server -->|2. 连接建立成功| Client Client -->|3. 创建 SMUX 会话| Server # 这里只调用了GET / Client -->|4. 请求 1: GET /| Server Cli 阅读全文

posted @ 2026-04-06 10:26 王景迁 阅读(1) 评论(0) 推荐(0)

2026年4月5日

[AI生成] 判断k8s deploy/statefulset是否已到达终态

摘要: package check_sts_deploy_status import ( "errors" "fmt" appsv1 "k8s.io/api/apps/v1" ) // IsDeploymentReady 检查 Deployment 是否到达终态 // 终态条件: // 1. Observe 阅读全文

posted @ 2026-04-05 11:44 王景迁 阅读(1) 评论(0) 推荐(0)

go 定义枚举值

摘要: go没有枚举类型,可以通过iota来定义枚举值。 package main import "fmt" type Status int const ( Unknown Status = iota Success Fail ) func main() { // 输出1 fmt.Println(Succe 阅读全文

posted @ 2026-04-05 09:11 王景迁 阅读(3) 评论(0) 推荐(0)

2026年3月21日

go net/http缺点和改进

摘要: go net/http在每次建立连接时,都会创建一个goroutine来处理,即一个连接绑定一个goroutine,在高并发情况消耗大量资源。 fasthttp在每次建立连接时,优先从工作池里面获取已有的处理对象,不够时再创建,即一个连接绑定一个goroutine。不同于go net/http库处理 阅读全文

posted @ 2026-03-21 17:18 王景迁 阅读(6) 评论(0) 推荐(0)

go http server优雅关闭Shutdown方法

摘要: go 1.24.0 用法 package main import ( "context" "log" "net/http" "os" "os/signal" "syscall" "time" ) func main() { mx := http.NewServeMux() mx.HandleFunc 阅读全文

posted @ 2026-03-21 15:49 王景迁 阅读(4) 评论(0) 推荐(0)

2026年3月20日

nginx配置总结

摘要: 开启debug日志 1. server里面增加error_log /var/log/nginx/debug.log debug;2. location里面增加不存在的测试后端proxy_pass http://172.17.0.3:8080;3. nginx -s reload 访问nginx ip 阅读全文

posted @ 2026-03-20 21:10 王景迁 阅读(2) 评论(0) 推荐(0)

k8s hostport

摘要: spec: containers: - image: nginx name: nginx ports: - containerPort: 80 hostPort: 8080 iptables增加dnat规则,完成主机端口8080到容器端口80的映射。 优点:固定转发到本节点pod。缺点:占用节点端口 阅读全文

posted @ 2026-03-20 20:30 王景迁 阅读(5) 评论(0) 推荐(0)

2026年3月7日

prometheus增加需要采集数据的pod

摘要: Prometheus serviceMonitorSelector ServiceMonitor(描述监控对象信息) matchLabels Service(k8s服务发现) Service+Deploy yaml定义 kind: Service apiVersion: v1 metadata: n 阅读全文

posted @ 2026-03-07 11:15 王景迁 阅读(2) 评论(0) 推荐(0)

2026年3月5日

go实现单机版限流

摘要: go get golang.org/x/time/rate package main import ( "log" "time" "golang.org/x/time/rate" ) func main() { // 创建一个每秒产生5个令牌,桶容量为10的限流器 log.Printf("调整前") 阅读全文

posted @ 2026-03-05 08:02 王景迁 阅读(5) 评论(0) 推荐(0)

导航