MCPcopy Index your code
hub / github.com/php/frankenphp / setAutomaticMaxThreads

Method setAutomaticMaxThreads

phpmainthread.go:162–178  ·  view source on GitHub ↗

max_threads = auto setAutomaticMaxThreads estimates the amount of threads based on php.ini and system memory_limit If unable to get the system's memory limit, simply double num_threads

()

Source from the content-addressed store, hash-verified

160// setAutomaticMaxThreads estimates the amount of threads based on php.ini and system memory_limit
161// If unable to get the system's memory limit, simply double num_threads
162func (mainThread *phpMainThread) setAutomaticMaxThreads() {
163 if mainThread.maxThreads >= 0 {
164 return
165 }
166 perThreadMemoryLimit := int64(C.frankenphp_get_current_memory_limit())
167 totalSysMemory := memory.TotalSysMemory()
168 if perThreadMemoryLimit <= 0 || totalSysMemory == 0 {
169 mainThread.maxThreads = mainThread.numThreads * 2
170 return
171 }
172 maxAllowedThreads := totalSysMemory / uint64(perThreadMemoryLimit)
173 mainThread.maxThreads = int(maxAllowedThreads)
174
175 if globalLogger.Enabled(globalCtx, slog.LevelDebug) {
176 globalLogger.LogAttrs(globalCtx, slog.LevelDebug, "Automatic thread limit", slog.Int("perThreadMemoryLimitMB", int(perThreadMemoryLimit/1024/1024)), slog.Int("maxThreads", mainThread.maxThreads))
177 }
178}
179
180//export go_frankenphp_shutdown_main_thread
181func go_frankenphp_shutdown_main_thread() {

Callers 1

Calls 1

TotalSysMemoryFunction · 0.92

Tested by

no test coverage detected