Page 1 of 2

CPU usage and (rail) network optimization

Posted: 18 May 2006 09:37
by gkirilov
I don't know if this is for this section or for "problems" but anyway..
I have a map with around 700 trains. I am using only presignals and the NPF is OFF. The CPU usage is around 60-70% with no ingame windows opened (with NPF ON it would go way above 100% ... if it could :D ).
My questions:
1. When I open 1 or 2 depot screens the CPU usage goes from 60% to 100% (the game becomes laggy). Why is that? The same goes for opening other ingame windows.
2. How to optimize the network or the orders so that the (default in this game 60%) CPU usage gets lower?
3. What else could be optimized?
4. Does the calculation of the money take a lot of resources. And if yes, do we really need the calcultaion to be done each milisecond(i have no idea how often it's done but i can see that the costs/profits are updated very often). It could be done every week or every 2 weeks (game time).

I'll post other question if i come up with something else.
p.s. my CPU is AMD Athlon 1800+ OC@2.1G

Posted: 18 May 2006 12:34
by bobingabout
i think the money is updates when something changes the amount of money you have, IE a delivery, daily running costs and other crap

Posted: 18 May 2006 12:52
by gkirilov
Hmm .. i guess then the frequesnt update(in terms of calculation) is necessary. What about displaying? Does it require a lot to display the calculated value so often (everytime it's updated)?

Posted: 18 May 2006 12:58
by bobingabout
now thats using your nogging, i supose its in the graphics display routines, so, not a lot could be done there either, unless you use OGL or DX, or some other graphics card acceleration...

Posted: 18 May 2006 15:08
by KING
i think breaking your tain routes into smaller pices with waypoints MIGHT help. So trains only go like 50 tiles between orders not 500

Posted: 19 May 2006 09:02
by zemei
you can try it on the yapf branch (I have win32 binary if you need it)
that is a yet another path finder, and i read that is faster than npf or pf

can you send me the map (email or msn) ?
i would like to try it

thanks

Posted: 19 May 2006 11:09
by Bjarni
it would be interesting to profile your savegame to see where the CPU spend time. I once wondered about trying to improve a part of the code and then I discovered that it only used 0,3% of the total CPU time. A 30% speed increase would have ment a 0,1% speed improvement overall. That's not worth the time so it's essential to actually measure where it eats up the CPU time as nobody would care for the many hours/days spent on getting that 0,1% speed improvement.

A good example of where profiling really mean something is when I used it to find a single line in the cocoa video driver that used more than 70% of the total CPU time (one single line :shock: ). Now it's reduced to less than 7% of the total CPU time and it can easily be seen in the game. I'm not sure I would have found a place to optimise with such a big impact without measuring where the CPU time went.

In short: we need the savegame and openttd.cfg to track down what eats the CPU time in this case, because guessing might not hit the right part of the code.

Posted: 19 May 2006 11:15
by gkirilov
Ok ..that would be really interesting. I'll post the files tonight.

There is only one problem. I am not using a nightly but a custom build with 4 patches (SirkoZ's smoke, economy and accelaration patches and minimap zoom patch). I'll post also the exe and the lng files.

Bjarni, can you give a short tutorial on how to trace the cpu usage. I have the cygwin currently installed.

Posted: 19 May 2006 11:18
by Bjarni
gkirilov wrote:Bjarni, can you give a short tutorial on how to trace the cpu usage. I have the cygwin currently installed.
I only know how to do it in OSX

also you have to enable profiling at compile time in Makefile.config, so an exe is not good on it's own unless you did this. Also you also need to use a profiling tool.

Posted: 21 May 2006 20:43
by gkirilov
So, I guess you don't need the exe for windows.
Here are the 4 patches and the save.

ps. sorry for the delay. No internet for 2 days.

Posted: 21 May 2006 20:59
by Bjarni
gkirilov wrote:So, I guess you don't need the exe for windows.
Here are the 4 patches and the save.
I will need openttd.cfg as well

Posted: 21 May 2006 22:07
by zemei
I tried it tonight. That's a great savegame, grat!

If I zoomed out the cpu usage was growed (i don't open any windows), so I think the same as Bjarni, it caused by the video driver.

But it is just my opinion! and i will go up to university just in September.

Posted: 21 May 2006 22:18
by Bjarni
zemei wrote:If I zoomed out the cpu usage was growed (i don't open any windows), so I think the same as Bjarni, it caused by the video driver.
Actually such a test is not a good one to find the cause of this. Say it's function X that uses most of the CPU and it got a constant load on the CPU. Now you increase CPU usage on the frame buffer generator by say 300% by zooming out (I have no idea if that is the right number), you will see an overall increase of CPU load without actually changing load in the part of the code, that kills the CPU.

Also I didn't say that it's the graphic driver, that is the cause of this, I just used it as an example of what I had done earlier with profiling, that really made a difference. In fact I think in this case it's something vehicle related. I will take a look once I got the config file and get time to do so.

Posted: 21 May 2006 23:22
by gkirilov
Sorry about the cfg. I knew that I've forgotten something.
(I am also using a lot of grfs.)

p.s. it is deffinetely something related to the vehicles, pathfinder or similar. Later in the game I switch to double(12 tiles) sized maglev trains (most of them in the save above are 6 tiles electric). So the number of trains was reduced a little and the CPU load dropped down by few percents.

Posted: 24 May 2006 13:10
by zemei
Bjarni:
sorry
i just don't understand anything what you write
my English knowledge is very poor

Posted: 24 May 2006 14:33
by Bjarni
zemei wrote:Bjarni:
sorry
i just don't understand anything what you write
my English knowledge is very poor
ok, I will try it like this:

say:
vehicles use 60% of the CPU
graphics (zoomed in) uses 15%
that's a total of 75%

now we zoom out:
vehicles use 60% of the CPU (unaffected)
graphics (way more tiles now) uses 40%
that's a total of 100%

now you increased CPU usage from 75% to 100% by zooming out, but the problem can still be the 60% used on vehicles.

Note: I just wrote some numbers for this example. They are likely way off, but it gives a good idea of what I mean

Posted: 24 May 2006 15:15
by Bjarni
gkirilov wrote:Sorry about the cfg. I knew that I've forgotten something.
(I am also using a lot of grfs.)
no kidding. It will take me ages to find all of them, so can you zip them?
gkirilov wrote:p.s. it is deffinetely something related to the vehicles, pathfinder or similar. Later in the game I switch to double(12 tiles) sized maglev trains (most of them in the save above are 6 tiles electric). So the number of trains was reduced a little and the CPU load dropped down by few percents.
like the zooming thing, it's not a proof, just an indication that you did something to reduce the total load.

Posted: 24 May 2006 17:30
by gkirilov
You can find all except the newstatsw.grf(too big to add and easy to find) in the .rar file.

Posted: 24 May 2006 18:16
by Wolf01
i have a little problem with this game: http://wolf01.game-host.org/ttsaves/Wol ... Routes.sav
is a 12*12/8Mb
the CPU usage is about 95% if i unpause the game, the game is really slow

i play on P4 3.02GHz, 512MB, ATi Mobility Radeon 9600 64Mb

Posted: 25 May 2006 10:48
by Bjarni
Wolf01 wrote:i have a little problem with this game: http://wolf01.game-host.org/ttsaves/Wol ... Routes.sav
is a 12*12/8Mb
the CPU usage is about 95% if i unpause the game, the game is really slow

i play on P4 3.02GHz, 512MB, ATi Mobility Radeon 9600 64Mb
it appears that an unusual amount of CPU time is allocated to find the nearest town for certain tiles. This is likely due to a large map with a whole lot of towns. Solution: get a faster computer :P

Maybe there is some room for improvement, but it's not an overnight thing, so maybe you should play with fewer towns and/or smaller maps.