This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
TheGeek's profile picture

[Question] Could a large number of computers running bad code slow a server?

Started by TheGeek, 22 November 2012 - 05:14 AM
TheGeek #1
Posted 22 November 2012 - 06:14 AM
On my hosted server, I have a compound with 4 computer controlled piston drawbridges. These drawbridges have one control computer that reads incoming RedNet messages, and outputs to other adjacent computers. Through some testing, we found that several computers worked better to control the array of pisons, IE one computer controlling one piston in a 2x8 array. This was due to computers being waterproof, and redstone being difficult to use.

The other computers in that array are running code similar to this:


while true do --main loop
sleep(0)
if redstone.getInput("left") then
  redstone.setOutput("top", true)
  redstone.setOutput("right", true)
else
  redstone.setOutput("top", false)
  redstone.setOutput("right", false)
end
end

Also keep in mind that we have 4 of these drawbridges around this compound, meaning a large number of computers are running this code.

I have been noticing some increased lag around this particular compound on our cheap hosted server, while my locally hosted test server doesn't have that same problem. My fear is that either one or both things are happening:

1. The un-optimized code running on all these computers is putting a large burden on my cheap linux virtual server
2. The large number of running computers in one chunk or one area is putting a large burden on my server

I could change the code to use os.eventPull to optimize it somewhat, but that would mean reprogramming all of those computers. I would rather redesign the drawbridges if the problem is too many computers.

I would be willing to post screenshots of the drawbridge array, if it would help diagnose the problem.

I look forward to your input.
Lyqyd #2
Posted 22 November 2012 - 06:36 AM
Replace sleep(0) with os.pullEvent("redstone"). This will cause it to resume the loop whenever the redstone input changes and not run otherwise, seriously reducing lag.
ChunLing #3
Posted 22 November 2012 - 10:10 AM
I say change the programming and redesign your bridge. The machine spirits are disturbed by your use of them to replace single redstone dusts…even if they are nearly that cheap.
Sammich Lord #4
Posted 22 November 2012 - 10:59 AM
You are constantly grabbing redstone input which causes a lot of lag.
TheGeek #5
Posted 22 November 2012 - 12:09 PM
I changed my code as you said, and it seems to have improved!

And as for the design, it wasn't my idea. It works, if a bit overcomplicated. And its waterproof incase any pesky creepers try to blow a hole in the wall and let the water moat in.
ChunLing #6
Posted 23 November 2012 - 03:40 AM
I'd say it's over-simplified rather than over-complicated. And the machine spirits are perturbed by the thought of being used to absorb creeper blasts.

If you're doing that, you should make sure to label the computers so that they don't lose their files on getting blown up (though this won't work in earlier versions of CC).

Or, if you're worried about creepers, use a self-healing design using several blocks of sand/gravel above the pistons.