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
()
| 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 |
| 162 | func (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 |
| 181 | func go_frankenphp_shutdown_main_thread() { |
no test coverage detected