Page 1 of 1

Does fluid/electricity flickering affect ups?

Posted: Fri Mar 24, 2023 7:41 pm
by Qilili
If you use circuit network conditions to change active volume without buffering, like "if tank > 20K : enable pump" and fluid will go back-and-forth fast around this number, does it have any negative consequences? Besides "not pretty".

Same for electricity with accumulators.

Re: Does fluid/electricity flickering effect ups

Posted: Fri Mar 24, 2023 7:56 pm
by jodokus31
Don't know, if UPS is tanked, but probably yes.
Here is a tip for the "not pretty" part
https://wiki.factorio.com/Tutorial:Circ ... er_version

Re: Does fluid/electricity flickering effect ups?

Posted: Fri Mar 24, 2023 8:30 pm
by mrvn
The term you are looking for is called hysteresis.

I'm not sure about the fluid system as I think that never sleeps. As soon as you have more than a pipe the fluid remains in motion at all times but the delta just gets incredible small.

The circuit network though has code that activate only when a signal changes. So a wire connected to a tank will update the signal every tick and that needs processing.

For power it is the worst I think. Every time you change a power switch the whole electrical network changes. The histogram on one side disappears and the entities are merged into a larger network. Solar panels might have to be recounted unless the code is smart enough to see when a panel is in both network and can merge the total number of panels smartly. Entities also slowly drain their internal buffer when they loose power and recharge it when they get power back. Once recharged their power demand changes to what they consume each tick. So there is a ton of extra work happening when your power switch flickers.
hysteresis.png
hysteresis.png (230.51 KiB) Viewed 1311 times
You can build a slow switch with or without hysteresis using 2 inserters, some belts, a wooden chest and any item. You configure one inserter to remove the wood when you have > 20k in the storage tank and the other to put it back with the reverse condition. Just the delay created by the belt will reduce the flickering, which is probably good for fluids. For power I would go for a hysteresis setup: Configure the second inserter to put the wood back when the tank is <10k. Then the factory with only switch back on when 10k has been produced or consumed, which will be far less often.

Note: you use the presence or absence of the item in the wooden chest to turn on/off the pump or switch.

Re: Does fluid/electricity flickering affect ups?

Posted: Sat Mar 25, 2023 6:48 am
by Qilili
So, the answer is "fluid may be not (it is already always moving), electricity most likely yes" (affects ups)


Nice trick with chest, but at this point you can as well just use 2-3 deciders.

Re: Does fluid/electricity flickering affect ups?

Posted: Sat Mar 25, 2023 12:38 pm
by jodokus31
The chest trick seems nice, if you haven't researched "circuit network" / "combinators".
You just have to have a blueprint and wires are build just fine.

And I like it visually.

Re: Does fluid/electricity flickering affect ups?

Posted: Sat Mar 25, 2023 1:56 pm
by mrvn
Yes you can use 2 combinators for a hysteresis. It's more useful without it, just as a slow switch.

But I like the visuality of it. Works great with an upgrade planer (green) or deconstruction planer (red) as item.

You can also use just a belt loop and read/hold instead of the chest. That way it doesn't even need power and you can put it on the side of a power switch that gets cut off.

Re: Does fluid/electricity flickering affect ups?

Posted: Sat Mar 25, 2023 3:15 pm
by Tertius
An attempt to answer the OP:
"Fluid flickering" if meant as toggling some pump every tick, isn't relevant to UPS, because fluid behavior is calculated anyway and fluidboxes are not going to sleep internally. The pump state just determines if fluid is transferred from its input to its output or not. One more operation per pump, and as long as you don't have 100000 pumps, it will probably not affect UPS. So just use a simple ">20K" condition without hysteresis.

"Electricity flickering" if meant as connecting/disconnecting electric networks with a power switch will probably affect UPS, because if 2 disconnected networks are being connected if you activate a power switch, the merging will consume some additional CPU the tick the switch is toggled. The same with disconnecting, when 1 electric network is being split into 2. Separating networks and occasionally (less than once a second) switching off inactive parts of a factory might improve UPS, because unpowered entities might go to sleep and not consume any CPU on update, but if you frequently toggle a power switch (every other tick), the overhead of merging/splitting the network is probably bigger than the savings with entities going inactive.

I bet people made benchmarks about this in the past.

I separated electric networks for smelter arrays. If the output chests of a plate smelter train station are full, or if the input chests are empty and no plates are flowing out of the smelters any more, I turn off all the electric furnaces and all their beacons. Looks smart, saves some MW of power if inactive, and I have the illusion that I optimized my factory. Dunno if this is really the case.

Re: Does fluid/electricity flickering affect ups?

Posted: Sun Mar 26, 2023 7:29 am
by Qilili
Tertius wrote:
Sat Mar 25, 2023 3:15 pm
Separating networks and occasionally (less than once a second) switching off inactive parts of a factory might improve UPS, because unpowered entities might go to sleep and not consume any CPU on update
I remember reading recently that it is opposite, unpowered entities are not sleeping because they are checking for power. So that "unpowering is very bad for ups".

Re: Does fluid/electricity flickering affect ups?

Posted: Sun Mar 26, 2023 8:14 am
by Stringweasel
Seperate networks are not good for UPS, but if you only have 3 then it's neglible. This has been tested.

All this talk is theorizing though, which is usually quite inaccurate because we don't know the source code, and optimization is hard.