[0.14] Reactors & Atomic Locomotives

Topics and discussion about specific mods
Post Reply
GotLag
Filter Inserter
Filter Inserter
Posts: 510
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by GotLag » Mon Apr 17, 2017 5:03 am

Vegemeister wrote:I'm playing Factorio on integrated graphics, and the game is already memory-bandwidth-bound to start with, so I have to worry about performance more than many of you. As my atomic-powered factory grew, it started dipping below 60 UPS (well, 59.9) at times. At first I was able to stave off the problem by switching my power plant to a combinator-free, pump-free design, and instead keeping a close eye on the power graph to make sure demand was comfortably between 20-100% of capacity.

At 50 reactors, that was no longer good enough. I turned on show_time_used_percent in the debug menu, and found that mod-Reactors itself was fluctuating between 3 and 4 milliseconds of execution time per update. Switching to solar would eliminate the problem, but that's not nearly as cool as atomic power. So I started tinkering.

I wasn't able to find anything online about using a profiler on a loaded Factorio mod, so I wrapped Factorio's --benchmark command line option in a bash script, and threw together some very ugly python to measure the performance across git commits.

I was able to considerably reduce the CPU usage of this mod, from ~3 ms/update to ~0.5 ms/update, as measured by the debug info with the GUI on. Changes were as follows:
  1. Time between full reactor updates increased from 5 ticks to 30 ticks.
  2. Reactor thermal mass increased and power increment/decrement decreased by a factor of 6, to preserve the control dynamics.
  3. Partial updates (which set the coolant temperature) run once every 5 ticks instead of on every tick.
  4. Coolant tank volume increased from 500 units to 2000 units, in order to counteract temperature sag from not running partial updates as frequently.
The benchmarks didn't have super-good test-retest consistency (always improvement, though), but here's a fairly representative run. The difference isn't as big as with the GUI on, because the headless benchmark means the simulation isn't competing with the iGPU for memory bandwidth:

Code: Select all

Commit   avg ms  min ms  max ms  Message
0076654    5.21    4.36   15.52  Update fluid temperature less often.
ef8d545    5.98    4.75   15.97  Refactor looping constructs.
5db3dd3    5.97    4.70   16.16  Update reactors less often.
7c81f64    6.66    5.42   16.50  Unix line endings.
7048c62    6.62    5.36   16.45  Initial commit
I don't know much about Factorio mod packaging/versioning and I don't want to step on anyone's toes, so I'm not gonna post a zip. But here's a patch:

Code: Select all

diff --git a/control.lua b/control.lua
index b20b17e..04b7df4 100644
--- a/control.lua
+++ b/control.lua
@@ -14,7 +14,8 @@ SIGNAL_REACTOR_TARGET = {type="virtual", name="signal-reactor-target"}
 SIGNAL_REACTOR_STOP = {type="virtual", name="signal-reactor-stop"}
 SIGNAL_REACTOR_STOPPING = {type="virtual", name="signal-reactor-stopping"}
 
-TICKS_PER_UPDATE = 5 -- each reactor and cooling tower gets updated once every 5 ticks
+TICKS_PER_UPDATE = 30 -- each reactor and cooling tower gets updated once every 30 ticks
+TICKS_PER_QUICK_UPDATE = 5 -- coolant temperature gets set once every 5 ticks
 UPDATES_PER_SECOND = 60 / TICKS_PER_UPDATE
 
 MAX_POWER = 26000 -- kilowatts
@@ -23,8 +24,8 @@ MIN_POWER =
   ["fission-reaction"] = MAX_POWER * 0.2,
   ["breeder-reaction"] = MAX_POWER * 0.2
 }
-POWER_INCREMENT = MAX_POWER / UPDATES_PER_SECOND / 10 -- 10 seconds to max from zero
-POWER_DECREMENT = MAX_POWER / UPDATES_PER_SECOND / 10 -- 10 seconds to zero from max
+POWER_INCREMENT = MAX_POWER / UPDATES_PER_SECOND / 60 -- 60 seconds to max from zero
+POWER_DECREMENT = MAX_POWER / UPDATES_PER_SECOND / 60 -- 60 seconds to zero from max
 CRAFTING_INCREMENT =
 {
   ["fission-reaction"] = 1 / 50 / UPDATES_PER_SECOND / MIN_POWER["fission-reaction"],
@@ -33,7 +34,7 @@ CRAFTING_INCREMENT =
 AMBIENT_TEMP = 15
 OPERATING_TEMP = 150
 SCRAM_TEMP = 200 -- overheat trigger temp
-REACTOR_MASS = 2000
+REACTOR_MASS = 12000
 
 function init_global()
   global = global or {}
@@ -304,6 +305,9 @@ end
 
 function update_reactor(index)
   local reactor = global.reactors[index]
+  if not reactor then
+    return
+  end
   
   -- update core
   if reactor.scram then
@@ -413,20 +417,15 @@ function update_tower(index)
 end
 
 script.on_event(defines.events.on_tick, function(event)
-  for i,_ in pairs(global.reactors) do
+  local quick_offset = (event.tick % TICKS_PER_QUICK_UPDATE) + 1
+  for i=quick_offset, #global.reactors, TICKS_PER_QUICK_UPDATE do
     quick_update_reactor(i)
   end
-  local index = (event.tick % TICKS_PER_UPDATE) + 1
-  while index <= #global.reactors do
-    if global.reactors[index] then
-      update_reactor(index)
-    end
-    index = index + TICKS_PER_UPDATE
+  local offset = (event.tick % TICKS_PER_UPDATE) + 1
+  for i=offset, #global.reactors, TICKS_PER_UPDATE do
+    update_reactor(i)
   end
-
-  index = (event.tick % TICKS_PER_UPDATE) + 1
-  while index <= #global.towers do
-    update_tower(index)
-    index = index + TICKS_PER_UPDATE
+  for i=offset, #global.towers, TICKS_PER_UPDATE do
+    update_tower(i)
   end
 end)
diff --git a/prototypes/entities.lua b/prototypes/entities.lua
index 860fdda..f64bbae 100644
--- a/prototypes/entities.lua
+++ b/prototypes/entities.lua
@@ -168,7 +168,7 @@ reactor_boiler =
   selection_box = {{-1.5,-1.5},{1.5,1.5}},
   fluid_box =
   {
-    base_area = 50,
+    base_area = 200,
     pipe_covers = pipecoverspictures(),
     pipe_connections =
     {
@@ -474,4 +474,4 @@ data:extend({
   cooling_tower_steam,
   turbine,
   peak_turbine
-})
\ No newline at end of file
+})
Nice work. I originally made this mod as a test of the reactor model, and released it after it seemed to work, I never really tried too hard to optimise it.

I'm not sure if it's worth releasing an update at this stage, given how close 1.5 apparently is, but I'm more than happy for you to share your fix. If you want to zip it all up with the mod you're welcome to do that as well.
Optera wrote:Maybe you could provide an "official" dumbed down version for us potato users GotLag. ;)
What's the performance like on Vegemeister's version?

Vegemeister
Long Handed Inserter
Long Handed Inserter
Posts: 68
Joined: Sun Dec 04, 2016 9:18 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by Vegemeister » Mon Apr 17, 2017 12:15 pm

GotLag wrote: Nice work. I originally made this mod as a test of the reactor model, and released it after it seemed to work, I never really tried too hard to optimise it.

I'm not sure if it's worth releasing an update at this stage, given how close 1.5 apparently is, but I'm more than happy for you to share your fix. If you want to zip it all up with the mod you're welcome to do that as well.
Optera wrote:Maybe you could provide an "official" dumbed down version for us potato users GotLag. ;)
What's the performance like on Vegemeister's version?
Alright, here it is. You'll have to rename the file to Reactors_1.6.0.zip, since it has to match the directory inside (or maybe the manifest; as I said IDK much about mod packaging).

Aside: Wow, 20 GW.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2089
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by Optera » Tue Apr 18, 2017 6:44 am

GotLag wrote:What's the performance like on Vegemeister's version?
Tested on an empty map with 5 blocks of 8 reactors each, under full load of ~1GW.

Reactors 1.6.0: UPS ~2.4
base
Vegemeister's Patch: UPS ~0.5
patched
I didn't expect such a huge performance improvement.
However with the patch fluid temperature curve is way too logarithmic. This is especially visible when recovering from emergency shutdown.
With one cooling tower water inside the reactor reaches 25°C after 4 minutes, but takes another 4 minutes to drop to 15°C.

PS: You should set reactor-interface.flags = {"hidden"} instead of "goes-to-quickbar" to prevent CreativeMode building interfaces without reactor connection.
For more compability you should also add the following to on_init and on_configuration_changed

Code: Select all

  if game.active_mods["creative-mode"] then
    remote.call("creative-mode", "exclude_from_instant_blueprint", "reactor-interface")
  end

GotLag
Filter Inserter
Filter Inserter
Posts: 510
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by GotLag » Tue Apr 25, 2017 1:12 pm

So far I'm not planning to port Reactors to 0.15, as the new vanilla reactors work just fine. I have uploaded a new version of Atomic Locomotives, renamed to Nuclear Locomotives for 0.15.

I've made a new thread for the new mod.

paralift
Manual Inserter
Manual Inserter
Posts: 1
Joined: Thu Apr 13, 2017 1:32 am
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by paralift » Tue Apr 25, 2017 1:22 pm

GotLag wrote:So far I'm not planning to port Reactors to 0.15, as the new vanilla reactors work just fine
just made an account cause your mod is one of my favorites

i havent played 0.15 but i i feel like i enjoy the way you handled nuclear power more than what we got in vanilla

and im sure im not the only one who would be super happy about an 0.15 update of Reactors as an alternative for those who like the cooling tower and circuit aspect

Marc90
Inserter
Inserter
Posts: 37
Joined: Wed Oct 07, 2015 5:42 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by Marc90 » Thu Apr 27, 2017 4:00 pm

Please update the mod to 0.15. I really like how it's done and my base heavily relies on the mod. I can't update to 0.15 without this mod or I would have to restart from scratch. (using only laser turrets as defense I'm lost without electricity)

I had some steam-engines for backup power, but those aren't working without a complete rebuild either in 0.15.

Well after all it's your decision and if you decide to not update I'll find another solution.
Just wanted to say that I'd be really sad if this mod is discontinued. It's one of my favorites.

GotLag
Filter Inserter
Filter Inserter
Posts: 510
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by GotLag » Thu Apr 27, 2017 9:41 pm

I'm not porting Reactors to 0.15. I think the new reactors actually work quite well, and I have other demands on my time.

I suggest you play around with the new reactors in sandbox mode to get a feel for how they work and what else has changed, and then decide from there if you want to continue your map or start a new one.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2089
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by Optera » Fri Apr 28, 2017 6:31 am

Base reactors are quite potent, a 2x4 group can easily produce over 1GW.
However I really prefer your fuel (re-)processing and models over the base game with that ugly assimilated potato.

nagapito
Filter Inserter
Filter Inserter
Posts: 357
Joined: Fri Jul 29, 2016 12:18 am
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by nagapito » Wed May 03, 2017 2:35 pm

GotLag wrote:I'm not porting Reactors to 0.15. I think the new reactors actually work quite well, and I have other demands on my time.

I suggest you play around with the new reactors in sandbox mode to get a feel for how they work and what else has changed, and then decide from there if you want to continue your map or start a new one.
I know its not needed but I have this 'dev honor' about others efforts so...
Do you give permission to anyone who wishes to fork and update your mod to v15?

GotLag
Filter Inserter
Filter Inserter
Posts: 510
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by GotLag » Wed May 03, 2017 2:38 pm

Knock yourself out.

deimosian
Burner Inserter
Burner Inserter
Posts: 12
Joined: Sat Oct 08, 2016 5:58 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by deimosian » Wed Jul 26, 2017 2:15 am

GotLag wrote:I'm not porting Reactors to 0.15. I think the new reactors actually work quite well, and I have other demands on my time.
I'm with Optera, I understand you have other priorities, but I find it unfortunate because I think your reactors and processing were done better than the new vanilla ones (and I've been playing vanilla 0.15 for awhile now). The sulfur mining is neat but the heat piping just feels gimmicky by comparison. Hopefully you revisit this one day, perhaps after 1.0 releases, and overhaul the vanilla reactors to act more like these.

xeln4g4
Inserter
Inserter
Posts: 38
Joined: Fri Oct 28, 2016 2:42 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by xeln4g4 » Fri Sep 22, 2017 6:54 pm

deimosian wrote:
GotLag wrote:I'm not porting Reactors to 0.15. I think the new reactors actually work quite well, and I have other demands on my time.
I'm with Optera, I understand you have other priorities, but I find it unfortunate because I think your reactors and processing were done better than the new vanilla ones (and I've been playing vanilla 0.15 for awhile now). The sulfur mining is neat but the heat piping just feels gimmicky by comparison. Hopefully you revisit this one day, perhaps after 1.0 releases, and overhaul the vanilla reactors to act more like these.
100% agree, please update your mod for the community!!!

GotLag
Filter Inserter
Filter Inserter
Posts: 510
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by GotLag » Fri Dec 15, 2017 10:15 am

I'll look into it.

User avatar
IngoKnieto
Long Handed Inserter
Long Handed Inserter
Posts: 97
Joined: Mon Oct 03, 2016 9:29 am
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by IngoKnieto » Thu Dec 21, 2017 6:07 pm

GotLag wrote:I'll look into it.
Awesome! I still like your Nuclear Reactors (and mostly it's overheating behavior) more than the Vanilla ones.

I think a 'slim' version of your mod, which just replaces the nuclear power plant buildings from vanilla game (power plant, heat exchanger, steam turbine) with your buildings, would be neat. Then you don't have to take care of the uranium ore and it's production chain...

xeln4g4
Inserter
Inserter
Posts: 38
Joined: Fri Oct 28, 2016 2:42 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by xeln4g4 » Tue Jan 16, 2018 11:29 pm

Any news on this? Please this was the best version of Reactor around, it was so satisfying to play with this!!!

GotLag
Filter Inserter
Filter Inserter
Posts: 510
Joined: Sat May 03, 2014 3:32 pm
Contact:

Re: [0.14] Reactors & Atomic Locomotives

Post by GotLag » Wed Jan 17, 2018 2:20 am

I'm unlikely to make a new version, but someone else has made a similar mod:
viewtopic.php?f=93&t=56621

Post Reply

Return to “Mods”

Who is online

Users browsing this forum: way