ID:97958
 
Not a bug
BYOND Version:471
Operating System:Windows Server 2003 R2
Web Browser:Firefox 3.6.6
Applies to:Dream Daemon
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
This proc:
proc/ResetGlobalStat(var/Stat,var/Value)
if(isnum(Value)) spawn(36000) GlobalTracked[Stat]-=Value

Is using over 10x the CPU of anything else in the game, and it does practically nothing. The proc that sets those stats to begin with is more complex, but it doesn't have a spawn() in it.
I have noticed this to.
I'm getting 0 CPU usage from even spamming spawn like so.
#define DEBUG
world
loop_checks=0
New()
..()
loopMyNum()
var/mynum = 0
proc/loopMyNum()
spawn(60)
mynum=!mynum
sleep(0.5)
loopMyNum()



EDIT-- Whoa holy crap.
at call 979 it stopped running completely. with 6.061 self CPU and 26.317 Total CPU
How do you check what codes are using how much CPU?
How many times is that being called though? If you're calling that more than once per value, then you're stacking up multiple copies of this reset that you don't need. There may be an error in the way the proc time is being tracked, but I wouldn't be too surprised if you simply have too many of these procs spawned.

A cleaner way to handle this would be an event loop.
globalstat
var/Stat
var/Value
var/reset

New(s,v)
Stat = s
Value = v
reset = world.time + 36000

var/list/GlobalTrackedReset = new
var/GlobalTrackedResetting

proc/ResettingGlobalStats()
GlobalTrackedResetting = 1
while(GlobalTrackedReset.len)
first = GlobalTrackedReset[1]
sleep(first.reset - world.time)
var/i
var/globalstat/first
for(i=1, i<=GlobalTracked.len, ++i)
first = GlobalTracked[i]
if(first.reset < world.time)
GlobalTraceked[first.Stat] -= first.Value
else break
if(i>1) GlobalTrackedReset.Cut(1,i)
GlobalTrackedResetting = 0

proc/ResetGlobalStat(Stat, Value)
var/globalstat/newstat = new(Stat,Value)
GlobalTrackedReset += first
if(GlobalTrackedResetting) return
spawn(-1) ResettingGlobalStats()
Lummox JR wrote:
How many times is that being called though?

The proc gets called A LOT, more or less every time anybody does anything.

If you're calling that more than once per value, then you're stacking up multiple copies of this reset that you don't need.

I have it tracking the actions of players over the last 60 minutes, so I need it to detract each value 60 minutes after it was logged?

There may be an error in the way the proc time is being tracked, but I wouldn't be too surprised if you simply have too many of these procs spawned.

I probably do have too many of them. However, there is a per-player call and then a global one that gets called before this reset. Neither of them use any CPU and both are more complex. I figured a call to spawn would just throw this on some imaginary back-burner somewhere never to exist again until the timer was up.
This one thing has taken the game from nearly 0% to over 100% on a steady basis.

A cleaner way to handle this would be an event loop.

lol did you write that code here on the forums or something? Cause there are quite a few errors (most of which are actually just logic ones). I think I understand the basic concept though. But wouldn't creating an uncountable crapload of datums in a list be even more taxing than having the related number of procs waiting around?


Ryuk25 wrote:
How do you check what codes are using how much CPU?

DS: Right click the window in the task bar(?) - server - profile
or F1 - file menu - server - profile (both require control_freak to be off)
DD: File menu - world - profile
DM: Write your own code to run .profile (I think this also requires control_freak to be off)


Leur wrote:
sleep(0.5)

Sleeping for decimal amounts doesn't work o.O They either round up or down, I forget which, down I think.
That code isn't a very good comparison to whats going on here, its more like a short infinite loop.
I set up a system similar to the code you posted. It helped, thanks. There are 100,000+ of these things floating around at once, and the system isn't even tracking everything yet.
Falacy wrote:
I set up a system similar to the code you posted. It helped, thanks. There are 100,000+ of these things floating around at once, and the system isn't even tracking everything yet.

Falacy how do you check what code is using how Much CPU This would be really helpful to some games that I am hosting that use a lot of CPU.
Ryuk, in Dream Daemon and Dream Seeker there's a Profile option you can use. This question belongs on the developer forums, not in the comments to a bug report.