mirror of
https://github.com/Gouryella/drip.git
synced 2026-02-26 14:21:17 +00:00
- Removed the manual performance optimization configuration in main.go and replaced it with a new tuning module. - Add patterned GC tuning in server.go and tunnel_runner.go - Updated yamux configuration to a unified optimized configuration to improve throughput. - Implement connection pool preheating function to eliminate cold start delay. - Optimize session selection using a min-heap, reducing the time complexity from O(n) to O(log n). - Add a bufio.Reader pool and a buffer pool to reduce memory allocation. - Implement a fragmented lock manager to improve performance under high concurrency. - Adjust heartbeat and timeout configurations to suit high-throughput scenarios BREAKING CHANGE: Manual GC tuning configuration has been removed; automatic tuning mode is now used.
62 lines
962 B
Go
62 lines
962 B
Go
package tuning
|
|
|
|
import (
|
|
"runtime"
|
|
"runtime/debug"
|
|
)
|
|
|
|
type Mode int
|
|
|
|
const (
|
|
ModeClient Mode = iota
|
|
ModeServer
|
|
)
|
|
|
|
type Config struct {
|
|
GCPercent int
|
|
MemoryLimit int64
|
|
}
|
|
|
|
func DefaultClientConfig() Config {
|
|
total := int64(getSystemTotalMemory())
|
|
limit := total / 4
|
|
if limit < 64*1024*1024 {
|
|
limit = 64 * 1024 * 1024
|
|
}
|
|
return Config{
|
|
GCPercent: 100,
|
|
MemoryLimit: limit,
|
|
}
|
|
}
|
|
|
|
func DefaultServerConfig() Config {
|
|
total := int64(getSystemTotalMemory())
|
|
limit := total * 3 / 4
|
|
if limit < 128*1024*1024 {
|
|
limit = 128 * 1024 * 1024
|
|
}
|
|
return Config{
|
|
GCPercent: 200,
|
|
MemoryLimit: limit,
|
|
}
|
|
}
|
|
|
|
func Apply(cfg Config) {
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
if cfg.GCPercent > 0 {
|
|
debug.SetGCPercent(cfg.GCPercent)
|
|
}
|
|
if cfg.MemoryLimit > 0 {
|
|
debug.SetMemoryLimit(cfg.MemoryLimit)
|
|
}
|
|
}
|
|
|
|
func ApplyMode(mode Mode) {
|
|
switch mode {
|
|
case ModeClient:
|
|
Apply(DefaultClientConfig())
|
|
case ModeServer:
|
|
Apply(DefaultServerConfig())
|
|
}
|
|
}
|