diff --git a/package.json b/package.json index 469f516..ff548b3 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..20693f0 --- /dev/null +++ b/server/index.js @@ -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()