CPU usage and (rail) network optimization

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

User avatar
gkirilov
Chief Executive
Chief Executive
Posts: 696
Joined: 03 May 2005 09:32
Location: Othala

CPU usage and (rail) network optimization

Post 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
OTTDCoop NewGRF Pack|Different sets of GRFs for TTDPatch (some of them work in OTTD) - 1|- 2|GRF sets for OTTD|OTTD nightly
Image
I hooked up my accelerator to my brake lights. I hit the gas, people behind me stop, and I'm gone.
Understeer is when you hit the wall with the front of the car. Oversteer is when you hit the wall with the rear of the car. Horsepower is how fast you hit the wall. Torque is how far you take the wall with you. Spoilers and bodykits are how much of the wall you take with you. Rollcages and windownets are how much of a mess you leave on the wall.
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post 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
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]
User avatar
gkirilov
Chief Executive
Chief Executive
Posts: 696
Joined: 03 May 2005 09:32
Location: Othala

Post 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)?
OTTDCoop NewGRF Pack|Different sets of GRFs for TTDPatch (some of them work in OTTD) - 1|- 2|GRF sets for OTTD|OTTD nightly
Image
I hooked up my accelerator to my brake lights. I hit the gas, people behind me stop, and I'm gone.
Understeer is when you hit the wall with the front of the car. Oversteer is when you hit the wall with the rear of the car. Horsepower is how fast you hit the wall. Torque is how far you take the wall with you. Spoilers and bodykits are how much of the wall you take with you. Rollcages and windownets are how much of a mess you leave on the wall.
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post 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...
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]
KING
Traffic Manager
Traffic Manager
Posts: 180
Joined: 12 Dec 2005 08:03

Post 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
Image
zemei
Engineer
Engineer
Posts: 4
Joined: 07 Apr 2006 19:49
Location: Hungary (SZSZB)
Contact:

Post 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
always rock'n'roll !!!
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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.
User avatar
gkirilov
Chief Executive
Chief Executive
Posts: 696
Joined: 03 May 2005 09:32
Location: Othala

Post 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.
OTTDCoop NewGRF Pack|Different sets of GRFs for TTDPatch (some of them work in OTTD) - 1|- 2|GRF sets for OTTD|OTTD nightly
Image
I hooked up my accelerator to my brake lights. I hit the gas, people behind me stop, and I'm gone.
Understeer is when you hit the wall with the front of the car. Oversteer is when you hit the wall with the rear of the car. Horsepower is how fast you hit the wall. Torque is how far you take the wall with you. Spoilers and bodykits are how much of the wall you take with you. Rollcages and windownets are how much of a mess you leave on the wall.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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.
User avatar
gkirilov
Chief Executive
Chief Executive
Posts: 696
Joined: 03 May 2005 09:32
Location: Othala

Post 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.
Attachments
SMG3 Ltd., 4. Feb 2020.sav
(565.6 KiB) Downloaded 213 times
patches.zip
(9.44 KiB) Downloaded 194 times
OTTDCoop NewGRF Pack|Different sets of GRFs for TTDPatch (some of them work in OTTD) - 1|- 2|GRF sets for OTTD|OTTD nightly
Image
I hooked up my accelerator to my brake lights. I hit the gas, people behind me stop, and I'm gone.
Understeer is when you hit the wall with the front of the car. Oversteer is when you hit the wall with the rear of the car. Horsepower is how fast you hit the wall. Torque is how far you take the wall with you. Spoilers and bodykits are how much of the wall you take with you. Rollcages and windownets are how much of a mess you leave on the wall.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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
zemei
Engineer
Engineer
Posts: 4
Joined: 07 Apr 2006 19:49
Location: Hungary (SZSZB)
Contact:

Post 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.
always rock'n'roll !!!
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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.
User avatar
gkirilov
Chief Executive
Chief Executive
Posts: 696
Joined: 03 May 2005 09:32
Location: Othala

Post 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.
Attachments
openttd.cfg
(4.6 KiB) Downloaded 215 times
OTTDCoop NewGRF Pack|Different sets of GRFs for TTDPatch (some of them work in OTTD) - 1|- 2|GRF sets for OTTD|OTTD nightly
Image
I hooked up my accelerator to my brake lights. I hit the gas, people behind me stop, and I'm gone.
Understeer is when you hit the wall with the front of the car. Oversteer is when you hit the wall with the rear of the car. Horsepower is how fast you hit the wall. Torque is how far you take the wall with you. Spoilers and bodykits are how much of the wall you take with you. Rollcages and windownets are how much of a mess you leave on the wall.
zemei
Engineer
Engineer
Posts: 4
Joined: 07 Apr 2006 19:49
Location: Hungary (SZSZB)
Contact:

Post by zemei »

Bjarni:
sorry
i just don't understand anything what you write
my English knowledge is very poor
always rock'n'roll !!!
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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.
User avatar
gkirilov
Chief Executive
Chief Executive
Posts: 696
Joined: 03 May 2005 09:32
Location: Othala

Post by gkirilov »

You can find all except the newstatsw.grf(too big to add and easy to find) in the .rar file.
Attachments
used.rar
(930.33 KiB) Downloaded 195 times
OTTDCoop NewGRF Pack|Different sets of GRFs for TTDPatch (some of them work in OTTD) - 1|- 2|GRF sets for OTTD|OTTD nightly
Image
I hooked up my accelerator to my brake lights. I hit the gas, people behind me stop, and I'm gone.
Understeer is when you hit the wall with the front of the car. Oversteer is when you hit the wall with the rear of the car. Horsepower is how fast you hit the wall. Torque is how far you take the wall with you. Spoilers and bodykits are how much of the wall you take with you. Rollcages and windownets are how much of a mess you leave on the wall.
User avatar
Wolf01
Tycoon
Tycoon
Posts: 2016
Joined: 24 Apr 2004 10:43
Location: Venezia - Italia
Contact:

Post 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
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post 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.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: Bing [Bot] and 25 guests