MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / tuneSystemParameters

Method tuneSystemParameters

internal/nodes/node.go:1106–1180  ·  view source on GitHub ↗

检查系统

()

Source from the content-addressed store, hash-verified

1104
1105// 检查系统
1106func (this *Node) tuneSystemParameters() {
1107 if runtime.GOOS != "linux" || os.Getgid() != 0 {
1108 return
1109 }
1110
1111 if sharedNodeConfig == nil || !sharedNodeConfig.AutoSystemTuning {
1112 return
1113 }
1114
1115 type variable struct {
1116 name string
1117 minValue int
1118 maxValue int
1119 }
1120
1121 const dir = "/proc/sys"
1122
1123 // net
1124 var systemParameters = []variable{
1125 {name: "net.core.somaxconn", minValue: 2048},
1126 {name: "net.ipv4.tcp_max_syn_backlog", minValue: 2048},
1127 {name: "net.core.netdev_max_backlog", minValue: 4096},
1128 {name: "net.ipv4.tcp_fin_timeout", maxValue: 10},
1129 {name: "net.ipv4.tcp_max_tw_buckets", minValue: 65535},
1130 {name: "net.core.rmem_default", minValue: 4 << 20},
1131 {name: "net.core.wmem_default", minValue: 4 << 20},
1132 {name: "net.core.rmem_max", minValue: 32 << 20},
1133 {name: "net.core.wmem_max", minValue: 32 << 20},
1134 {name: "vm.max_map_count", minValue: 256 << 10},
1135 }
1136
1137 // vm
1138 var systemMemory = memutils.SystemMemoryGB()
1139 if systemMemory >= 128 {
1140 systemParameters = append(systemParameters, []variable{
1141 {name: "vm.dirty_background_ratio", minValue: 40},
1142 {name: "vm.dirty_ratio", minValue: 60},
1143 }...)
1144 } else if systemMemory >= 64 {
1145 systemParameters = append(systemParameters, []variable{
1146 {name: "vm.dirty_background_ratio", minValue: 30},
1147 {name: "vm.dirty_ratio", minValue: 50},
1148 }...)
1149 } else if systemMemory >= 16 {
1150 systemParameters = append(systemParameters, []variable{
1151 {name: "vm.dirty_background_ratio", minValue: 15},
1152 {name: "vm.dirty_ratio", minValue: 30},
1153 }...)
1154 }
1155
1156 for _, v := range systemParameters {
1157 var path = dir + "/" + strings.Replace(v.name, ".", "/", -1)
1158 data, err := os.ReadFile(path)
1159 if err != nil {
1160 continue
1161 }
1162 data = bytes.TrimSpace(data)
1163 if len(data) == 0 {

Callers 1

StartMethod · 0.95

Calls 3

PrintlnFunction · 0.92
WriteFileMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected