node进程

This commit is contained in:
2023-10-14 06:42:45 +08:00
parent 42bf38a863
commit 94a203427f
2 changed files with 37 additions and 2 deletions

View File

@ -6,8 +6,8 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"serve": "vite preview",
"test": "echo \"Error: no test specified\" && exit 1"
"preview": "vite preview",
"start": "node server/index.js"
},
"devDependencies": {
"vite": "^2.6.4"

35
server/index.js Normal file
View File

@ -0,0 +1,35 @@
'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()