perf: 优化后端性能与直播延迟,包含数据库WAL模式、流媒体写缓冲、转码 Preset 优化、聊天锁和指标采集优化,以及前端自动追帧功能

This commit is contained in:
2026-06-15 15:08:07 +08:00
parent 261b1ab169
commit e0a6923984
5 changed files with 150 additions and 24 deletions

View File

@@ -29,14 +29,23 @@ func InitDB() {
)
var err error
// Use SQLite database stored in a local file named "hightube.db"
DB, err = gorm.Open(sqlite.Open("hightube.db"), &gorm.Config{
// Use SQLite database stored in a local file named "hightube.db" with WAL mode and busy timeout enabled
DB, err = gorm.Open(sqlite.Open("hightube.db?_journal_mode=WAL&_busy_timeout=5000"), &gorm.Config{
Logger: newLogger,
})
if err != nil {
log.Fatalf("Failed to connect database: %v", err)
}
// Configure connection pool settings
sqlDB, err := DB.DB()
if err != nil {
log.Fatalf("Failed to get database instance: %v", err)
}
sqlDB.SetMaxOpenConns(10)
sqlDB.SetMaxIdleConns(5)
sqlDB.SetConnMaxLifetime(time.Hour)
// Auto-migrate the schema
err = DB.AutoMigrate(&model.User{}, &model.Room{})
if err != nil {
@@ -48,7 +57,7 @@ func InitDB() {
ensureAdminUser()
monitor.Infof("Database initialized successfully")
monitor.Infof("Database initialized successfully with WAL mode and connection pooling")
}
func ensureAdminUser() {