sakuya/server/index.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-10-14 06:42:45 +08:00
'use strict'
// 规则
// 1. 持续运行
// 2. 周期回归
// 3. 锚点小模型
// 4. 基础规律模型
async function thinking(x, n = 0) {
if (x === 'x') return 'xD'
if (n > 1024) return x + 'De'
return await thinking(x, n + 1)
}
async function main(tasks = []) {
while (true) {
const task = tasks.pop() // 取一个任务(后进先出)
// 执行任务(了解任务目标, 前提是认知目标和其宏观原理)
// 寻找方法(了解寻找方法的原理, 以及方法的优劣分辨)
// 尝试解法(分支扩展拟合, 或全局拟合)
// 执行一次thinking
//await thinking('x')
// 内存低于1GB时终止进程
if (process.memoryUsage().rss > 1024 * 1024 * 1024) {
console.log('内存不足,进程终止')
process.exit()
}
// 每秒一次打印当前进程占用的内存
await new Promise((resolve) => setTimeout(resolve, 100))
const used = process.memoryUsage().heapUsed / 1024 / 1024
console.log(`内存使用 ${Math.round(used * 100) / 100} MB`)
}
}
main()