Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cluster from 'cluster'
- let arr = []
- function genRandomString(ts) {
- let i = 16 * 1024
- while (i--) {
- arr.push(Date.now().toString().repeat(79))
- }
- if (arr.length > i * 2 ) {
- arr = []
- // arr.length = Math.trunc(Math.random() * arr.length)
- }
- setTimeout(() => genRandomString(ts), ts)
- }
- if (cluster.isPrimary) {
- genRandomString(200)
- console.log("fork cluster!")
- const arr = []
- let i = 11
- while (i--) {
- const work = cluster.fork()
- arr.push(work)
- }
- cluster.on("message", (work, message) => {
- work._tt = message
- })
- setInterval(() => {
- const tArr = arr.map(w => [w.process.pid, w._tt])
- if (tArr.some(item => item[1] !== tArr[0][1]))
- console.log(tArr.join(", "))
- }, 5000)
- } else {
- console.log(new Date().toLocaleTimeString() + " fork" + process.pid)
- setInterval(() => {
- process.send(new Date().toLocaleTimeString())
- // console.log(new Date().toLocaleTimeString() + " " + process.pid)
- }, 2000)
- genRandomString(200)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement