This commit is contained in:
lunaticbum 2026-03-27 17:08:12 +09:00
parent 0479d5777a
commit 9803b27741
2 changed files with 56 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package service
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import network.RagService
import util.HardwareDetector
@ -47,6 +48,24 @@ object LlamaServerManager {
}
}
fun checkPortStatus(port: Int): String {
return try {
// netstat 명령어로 해당 포트를 점유 중인 프로세스 확인
val process = Runtime.getRuntime().exec("cmd /c netstat -ano | findstr :$port")
val reader = process.inputStream.bufferedReader()
val result = reader.readText()
if (result.contains("LISTENING")) {
val pid = result.trim().split(Regex("\\s+")).last()
"✅ 포트 $port 상태: 사용 중 (PID: $pid - 정상 대기 중)"
} else {
"⚠️ 포트 $port 상태: 리스닝 상태가 아님 (서버 미구동 또는 차단 가능성)"
}
} catch (e: Exception) {
"❌ 포트 점검 실패: ${e.message}"
}
}
fun startServer(binPath: String, modelPath: String, port: Int) {
if (processes.containsKey(port) || modelPath.isBlank()) return
@ -64,8 +83,10 @@ object LlamaServerManager {
val optimalThreads = (cpuCores * ratio).toInt().coerceIn(4, 16)
// 2. optimalGpuLayers: GPU 가속 조건 (윈도우 NVIDIA 또는 맥 ARM)
val optimalGpuLayers = if ((isWin && hasGpu) || isMacArm) 99 else 4
var optimalGpuLayers = if ((isWin && hasGpu) || isMacArm) 99 else 4
if(HardwareDetector.getCpuName().contains("i7")) {
optimalGpuLayers = 0
}
println("🖥️ OS: $os / Arch: $arch")
println("⚙️ 할당 스레드: $optimalThreads (Core: $cpuCores, Ratio: $ratio)")
println("🚀 GPU 레이어: $optimalGpuLayers (NVIDIA/MacArm: ${if(optimalGpuLayers == 99) "YES" else "NO"})")
@ -117,6 +138,14 @@ object LlamaServerManager {
processes[port] = process
println("✅ AI 서버 시작 시도 (Port: $port, Model: ${File(modelPath).name})")
delay(3000)
val status = checkPortStatus(port)
println(status) // 콘솔 로그
// UI 로그 스토어에도 기록 (TradingDecisionLog 등에서 확인 가능)
TradingLogStore.addAnalyzer("System", "Port:$port", status, status.contains(""))
val reader = BufferedReader(InputStreamReader(process.inputStream))
var line: String?
while (reader.readLine().also { line = it } != null) {

View File

@ -18,4 +18,29 @@ object HardwareDetector {
false
}
}
fun getWindowsCpuName(): String {
return try {
val process = Runtime.getRuntime().exec("wmic cpu get name")
val reader = process.inputStream.bufferedReader()
reader.readLine() // 첫 줄(Name) 건너뛰기
reader.readLine()?.trim() ?: "Unknown CPU"
} catch (e: Exception) {
"Error detecting CPU"
}
}
fun getMacCpuName(): String {
return try {
val process = Runtime.getRuntime().exec("sysctl -n machdep.cpu.brand_string")
process.inputStream.bufferedReader().readLine()?.trim() ?: "Unknown Apple Silicon"
} catch (e: Exception) {
"Error detecting CPU"
}
}
fun getCpuName(): String {
val os = System.getProperty("os.name").lowercase()
return if (os.contains("win")) getWindowsCpuName() else getMacCpuName()
}
}