Skip to content

待办清单 ​

TODO ​

  • 边缘计算 Serverless Hono
    • Hono 的目标不是传统服务器,而是跑在边缘节点 / serverless runtime 上
  • Cloudflare 产品
  • 系统设计思维:分片、主备、副本、选举(Leader/Follower)
    • 系统设计:后端架构、分布式系统、缓存、消息队列、一致性等知识
  • 必知必会的组件
  • 使用 Prometheus/Grafana 实时监控应用的 WebSocket 的连接数
  • 云厂商必知必会 云计算/边缘云
    • 阿里云
    • 腾讯云
    • 火山引擎
    • AWS/Azure
    • Google Cloud -> BigQuery + AI Infra最强
    • Cloudflare
Details

实现的核心思路是在你的应用代码中引入 Prometheus 客户端库,定义一个 Gauge 指标,然后在每次 WebSocket 连接建立或断开时,同步更新这个指标的数值

最后,通过一个 /metrics HTTP 端点让 Prometheus 来抓取

go
package main

import (
    "net/http"
    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)

// 1. 定义Gauge指标
var (
    websocketConcurrent = prometheus.NewGauge(prometheus.GaugeOpts{
        Name: "websocket_connections_total",
        Help: "Current total WebSocket connections.",
    })
)

func init() {
    // 注册指标
    prometheus.MustRegister(websocketConcurrent)
}

// 在你的WebSocket处理函数中
func handleWebSocket(w http.ResponseWriter, r *http.Request) {
    // 2. 连接打开,增加计数
    websocketConcurrent.Inc()

    // 使用defer确保连接关闭时计数一定减少,即使发生panic
    defer websocketConcurrent.Dec()

    // 你的WebSocket业务逻辑...
}

func main() {
    // 3. 暴露/metrics端点给Prometheus抓取
    http.Handle("/metrics", promhttp.Handler())
    // 你的应用主逻辑...
    http.ListenAndServe(":8080", nil)
}
  • 开发一个微信小程序
  • MapReduce 已死,流处理与批处理 Spark 和 Flink,用更高级的抽象解决了一切

资料整理 ​