⚡ Optimize memory usage
This commit is contained in:
parent
b006d29f53
commit
5ccbc592b7
@ -31,6 +31,10 @@ type RoadTraceError struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *RoadMetrics) AddTrace(trace RoadTrace) {
|
func (v *RoadMetrics) AddTrace(trace RoadTrace) {
|
||||||
|
if viper.GetBool("performance.low_memory") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
v.TotalTraffic++
|
v.TotalTraffic++
|
||||||
trace.Timestamp = time.Now()
|
trace.Timestamp = time.Now()
|
||||||
if _, ok := v.Traffic[trace.Region]; !ok {
|
if _, ok := v.Traffic[trace.Region]; !ok {
|
||||||
@ -48,12 +52,12 @@ func (v *RoadMetrics) AddTrace(trace RoadTrace) {
|
|||||||
|
|
||||||
// Garbage recycle
|
// Garbage recycle
|
||||||
if len(v.Traffic) > viper.GetInt("performance.traces_limit") {
|
if len(v.Traffic) > viper.GetInt("performance.traces_limit") {
|
||||||
v.Traffic = make(map[string]int64)
|
clear(v.Traffic)
|
||||||
}
|
}
|
||||||
if len(v.TrafficFrom) > viper.GetInt("performance.traces_limit") {
|
if len(v.TrafficFrom) > viper.GetInt("performance.traces_limit") {
|
||||||
v.TrafficFrom = make(map[string]int64)
|
clear(v.TrafficFrom)
|
||||||
}
|
}
|
||||||
if len(v.Traces) > viper.GetInt("performance.traces_limit") {
|
if len(v.Traces) > viper.GetInt("performance.traces_limit") {
|
||||||
v.Traces = v.Traces[1:]
|
clear(v.Traces)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ request_logging = true
|
|||||||
capture_traces = true
|
capture_traces = true
|
||||||
|
|
||||||
[performance]
|
[performance]
|
||||||
|
low_memory = true
|
||||||
traces_limit = 256
|
traces_limit = 256
|
||||||
prefork = false
|
prefork = false
|
||||||
|
|
||||||
|
1
test/data/.gitignore
vendored
1
test/data/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
|
/spa
|
||||||
/capital
|
/capital
|
||||||
/static-files
|
/static-files
|
@ -1,9 +1,9 @@
|
|||||||
id = "example"
|
id = "static-files"
|
||||||
|
|
||||||
[[locations]]
|
[[locations]]
|
||||||
id = "example-location"
|
id = "static-files-loc"
|
||||||
host = ["localhost:8000"]
|
hosts = ["localhost:8000"]
|
||||||
path = ["/"]
|
paths = ["/"]
|
||||||
[[locations.destinations]]
|
[[locations.destinations]]
|
||||||
id = "example-destination"
|
id = "static-files-des"
|
||||||
uri = "files://../data/spa?fallback=index.html"
|
uri = "files://../data/spa?fallback=index.html"
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
|
id = "central-dc"
|
||||||
|
|
||||||
[debug]
|
[debug]
|
||||||
print_routes = true
|
print_routes = false
|
||||||
|
|
||||||
|
[sideload]
|
||||||
|
ports = [":81"]
|
||||||
|
secured_ports = []
|
||||||
|
trusted_proxies = ["localhost"]
|
||||||
|
|
||||||
[hypertext]
|
[hypertext]
|
||||||
sideload_ports = [":81"]
|
|
||||||
sideload_secured_ports = []
|
|
||||||
ports = [":8000"]
|
ports = [":8000"]
|
||||||
secured_ports = []
|
secured_ports = []
|
||||||
|
force_https = false
|
||||||
|
|
||||||
[hypertext.certificate]
|
# [[hypertext.certificate]]
|
||||||
redirect = false
|
# key = "./certs/privkey.pem"
|
||||||
sideload_key = "./cert.key"
|
# pem = "./certs/fullchain.pem"
|
||||||
sideload_pem = "./cert.pem"
|
|
||||||
key = "./cert.key"
|
|
||||||
pem = "./cert.pem"
|
|
||||||
|
|
||||||
[hypertext.limitation]
|
[hypertext.limitation]
|
||||||
max_body_size = 549_755_813_888 # 512 GiB
|
max_body_size = 549_755_813_888 # 512 GiB
|
||||||
@ -21,11 +24,13 @@ max_qps = -1
|
|||||||
[paths]
|
[paths]
|
||||||
configs = "./config"
|
configs = "./config"
|
||||||
|
|
||||||
[performance]
|
[telemetry]
|
||||||
request_logging = true
|
request_logging = true
|
||||||
network_timeout = 3_000
|
capture_traces = true
|
||||||
|
|
||||||
|
[performance]
|
||||||
|
traces_limit = 256
|
||||||
prefork = false
|
prefork = false
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
sideload_trusted_proxies = ["localhost"]
|
|
||||||
credential = "e81f43f32d934271af6322e5376f5f59"
|
credential = "e81f43f32d934271af6322e5376f5f59"
|
||||||
|
9
test/roadsign/config/static-files.toml
Executable file
9
test/roadsign/config/static-files.toml
Executable file
@ -0,0 +1,9 @@
|
|||||||
|
id = "static-files-num2"
|
||||||
|
|
||||||
|
[[locations]]
|
||||||
|
id = "static-files-loc-num2"
|
||||||
|
hosts = ["127.0.0.1:8000"]
|
||||||
|
paths = ["/"]
|
||||||
|
[[locations.destinations]]
|
||||||
|
id = "static-files-des-num2"
|
||||||
|
uri = "files://../data/static-files"
|
Loading…
Reference in New Issue
Block a user