23. os

const os = require('os');

// process 랑도 어느정도 겹친다.
// 운영체제 정보 --------------------------------
console.log(os.arch()); // arm64
console.log(process.arch); // arm64

console.log(os.platform()); // darwin
console.log(process.platform); // darwin

console.log(os.type()); // Darwin

console.log(os.uptime()); // 57603
console.log(process.uptime()); // 0.014229209

console.log(os.hostname()); // AL01598765.local

console.log(os.release()); // 21.6.0
console.log(process.release);
// {
//   name: 'node',
//   sourceUrl: 'https://nodejs.org/download/release/v19.7.0/node-v19.7.0.tar.gz',
//   headersUrl: 'https://nodejs.org/download/release/v19.7.0/node-v19.7.0-headers.tar.gz'
// }


// 경로 --------------------------------
console.log(os.homedir()); // /Users/xxxx

console.log(os.tmpdir()); // /var/folders/6p/64fw19cj2jg8j24xggqn7lcc0000gn/T

// CPU 정보 ----------------------------------------------------------------------------------------
console.log(os.cpus()); // 제일 많이 사용된다.
// 현재 CPU 정보가 나온다. // 코어 갯수에 따라 나온다.
// 이게 왜 중요하냐면, 서버를 띄울 때, 노드는 싱글 스레드라고 했잖아?
// 즉, 서버를 띄울 때, 싱글 스레드라 CPU를 1개밖에 사용 안한다.
// 그럼 아래와 같이 10개인 경우에 나머지 9개는 놀고있는 것이다.
// 효율적으로 일하려면 10개 모두 서버로 돌리면 된다.
//  - 이때 현재 10개까지 띄울 수 있다는 걸 알아내려면 os.cpus() 메서드를 사용해야된다.
// ------------------------------------------------------------------------------------------------
// 주의할 점
//  운영체제에서 8코어 16스레드 / 16코어 32스레드
//  위 스레드랑 이전에 말했던 스레드랑은 다른 스레드이다.
//  os의 스레드랑 노드의 스레드는 다른 스레드라는 것이다.
//  8코어 16스레드라고 홍보되는 PC는 16코어라고 생각하면된다.
//  하드웨어적으로 쓰이는 용어와 노드에서 쓰이는 용어가 뜻이 다를 수도 있다는 것이다.
// ------------------------------------------------------------------------------------------------
// [
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 1421260, nice: 0, sys: 933650, idle: 22770450, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 1423470, nice: 0, sys: 838020, idle: 22862800, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 411940, nice: 0, sys: 139970, idle: 24572400, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 270090, nice: 0, sys: 67130, idle: 24787080, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 175450, nice: 0, sys: 35440, idle: 24913410, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 134400, nice: 0, sys: 25590, idle: 24964310, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 116890, nice: 0, sys: 15000, idle: 24992430, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 91170, nice: 0, sys: 10500, idle: 25022640, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 77970, nice: 0, sys: 7550, idle: 25038800, irq: 0 }
//   },
//   {
//     model: 'Apple M1 Pro',
//     speed: 24,
//     times: { user: 72340, nice: 0, sys: 6290, idle: 25045690, irq: 0 }
//   }
// ]
console.log(process.cpuUsage()); // { user: 22520, system: 4969 }

// 메모리 정보 --------------------------------
console.log(os.freemem()); // 8485863424
console.log(os.totalmem()); // 34359738368