perf: 提升后端高并发承载能力

This commit is contained in:
2026-06-15 15:33:49 +08:00
parent 63c954da55
commit 8715c7bb3d
12 changed files with 600 additions and 151 deletions

View File

@@ -1,6 +1,9 @@
package main
import (
"net/http"
"time"
"hightube/internal/api"
"hightube/internal/chat"
"hightube/internal/db"
@@ -23,9 +26,16 @@ func main() {
// Start the API server in a goroutine so it doesn't block the RTMP server
go func() {
r := api.SetupRouter(srv)
httpServer := &http.Server{
Addr: ":8080",
Handler: r,
ReadHeaderTimeout: 5 * time.Second,
IdleTimeout: 60 * time.Second,
MaxHeaderBytes: 1 << 20,
}
monitor.Infof("API server listening on :8080")
monitor.Infof("Web console listening on :8080/admin")
if err := r.Run(":8080"); err != nil {
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
monitor.Errorf("Failed to start API server: %v", err)
}
}()