...
This commit is contained in:
parent
0479d5777a
commit
9803b27741
@ -3,6 +3,7 @@ package service
|
|||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.SupervisorJob
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import network.RagService
|
import network.RagService
|
||||||
import util.HardwareDetector
|
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) {
|
fun startServer(binPath: String, modelPath: String, port: Int) {
|
||||||
|
|
||||||
if (processes.containsKey(port) || modelPath.isBlank()) return
|
if (processes.containsKey(port) || modelPath.isBlank()) return
|
||||||
@ -64,8 +83,10 @@ object LlamaServerManager {
|
|||||||
val optimalThreads = (cpuCores * ratio).toInt().coerceIn(4, 16)
|
val optimalThreads = (cpuCores * ratio).toInt().coerceIn(4, 16)
|
||||||
|
|
||||||
// 2. optimalGpuLayers: GPU 가속 조건 (윈도우 NVIDIA 또는 맥 ARM)
|
// 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("🖥️ OS: $os / Arch: $arch")
|
||||||
println("⚙️ 할당 스레드: $optimalThreads (Core: $cpuCores, Ratio: $ratio)")
|
println("⚙️ 할당 스레드: $optimalThreads (Core: $cpuCores, Ratio: $ratio)")
|
||||||
println("🚀 GPU 레이어: $optimalGpuLayers (NVIDIA/MacArm: ${if(optimalGpuLayers == 99) "YES" else "NO"})")
|
println("🚀 GPU 레이어: $optimalGpuLayers (NVIDIA/MacArm: ${if(optimalGpuLayers == 99) "YES" else "NO"})")
|
||||||
@ -117,6 +138,14 @@ object LlamaServerManager {
|
|||||||
processes[port] = process
|
processes[port] = process
|
||||||
println("✅ AI 서버 시작 시도 (Port: $port, Model: ${File(modelPath).name})")
|
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))
|
val reader = BufferedReader(InputStreamReader(process.inputStream))
|
||||||
var line: String?
|
var line: String?
|
||||||
while (reader.readLine().also { line = it } != null) {
|
while (reader.readLine().also { line = it } != null) {
|
||||||
|
|||||||
@ -18,4 +18,29 @@ object HardwareDetector {
|
|||||||
false
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user