Skip to content

Commit

Permalink
Swaps to unix sys package.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alliballibaba2 committed Jan 10, 2025
1 parent 83e0c08 commit 79447b8
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 48 deletions.
2 changes: 1 addition & 1 deletion frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func Init(options ...Option) error {
initAutoScaling(mainThread.numThreads, mainThread.maxThreads)

if c := logger.Check(zapcore.InfoLevel, "FrankenPHP started 🐘"); c != nil {
c.Write(zap.String("php_version", Version().Version), zap.Int("num_threads", totalThreadCount), zap.Int("max_threads", maxThreadCount))
c.Write(zap.String("php_version", Version().Version), zap.Int("num_threads", mainThread.numThreads), zap.Int("max_threads", mainThread.maxThreads))
}
if EmbeddedAppPath != "" {
if c := logger.Check(zapcore.InfoLevel, "embedded PHP app 📦"); c != nil {
Expand Down
15 changes: 0 additions & 15 deletions internal/memory/memory_bsd.go

This file was deleted.

13 changes: 0 additions & 13 deletions internal/memory/memory_darwin.go

This file was deleted.

16 changes: 0 additions & 16 deletions internal/memory/memory_linux.go

This file was deleted.

13 changes: 13 additions & 0 deletions internal/memory/memory_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package memory

import "golang.org/x/sys/unix"

func TotalSysMemory() uint64 {
sysInfo := &unix.Sysinfo_t{}
err := unix.Sysinfo(sysInfo)
if err != nil {
return 0
}

return uint64(sysInfo.Totalram) * uint64(sysInfo.Unit)
}
5 changes: 3 additions & 2 deletions phpmainthread.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func initPHPThreads(numThreads int, numMaxThreads int, phpIniOverrides map[strin
return nil
}

// ThreadDebugStatus prints the state of all PHP threads - debugging purposes only
func ThreadDebugStatus() string {
statusMessage := ""
reservedThreadCount := 0
Expand Down Expand Up @@ -173,13 +174,13 @@ func (mainThread *phpMainThread) setAutomaticMaxThreads() {
return
}
perThreadMemoryLimit := int64(C.frankenphp_get_current_memory_limit())
totalOSMemory := memory.Total()
totalOSMemory := memory.TotalSysMemory()
if perThreadMemoryLimit <= 0 || totalOSMemory == 0 {
return
}
maxAllowedThreads := totalOSMemory / uint64(perThreadMemoryLimit)
mainThread.maxThreads = int(maxAllowedThreads)
logger.Info("Automatic thread limit", zap.Int("phpMemoryLimit(MB)", int(perThreadMemoryLimit/1024/1024)), zap.Int("maxThreads", mainThread.maxThreads))
logger.Info("Automatic thread limit", zap.Int("perThreadMemoryLimitMB", int(perThreadMemoryLimit/1024/1024)), zap.Int("maxThreads", mainThread.maxThreads))
}

//export go_frankenphp_shutdown_main_thread
Expand Down
2 changes: 1 addition & 1 deletion scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func initAutoScaling(numThreads int, maxThreads int) {

func drainAutoScaling() {
scalingMu.Lock()
logger.Debug("shutting down autoscalin", zap.Int("num scaled threads", len(autoScaledThreads)))
logger.Debug("shutting down autoscalin", zap.Int("autoScaledThreads", len(autoScaledThreads)))
scalingMu.Unlock()
}

Expand Down

0 comments on commit 79447b8

Please sign in to comment.