Question about dcmd ans sscanf
#1

Are dcmd and sscanf supposed to be just faster or faster and more cpu friendly?

The reason i ask is, i was using strtok for all of my commands.

I had problems with the CPU usage going upto 80% at times when there was around 30 players in.

There was a lot of loops, and dumb pieces of script i wrote a long time ago and forgot about. I fixed them, and removed most.

Everything seemed fine, CPU was around 30% with around 30-40 in. Still pretty high, but there were no restarts due to CPU protection.


Then i changed all my admin commands to dcmd and used sscanf with them. This was only for my admin commands and used sscanf for my IRC commands.

The weird thing is, its showing more CPU usage than with strtok. Theres nothing else i've added since removing a load of stuff, the only change was my admin and irc commands from strtok to dcmd and sscanf.

Reply
#2

Maybe you have changed the order of commands at OnPlayerCommandText? Have you tried to change ALL commands to dcmd and sscanf?
Also you may try this system instead of dcmd, it should decrease your CPU usage.
Reply
#3

You can also use: YSI's ycmd system;

OnGameModeInit:
ycmd(command_name);

Somewhere:
Command_(command_name)
{
...
}

It is designed to maintain alot of commands and it is really dynamic such as live command renaming, etc.
Reply
#4

Quote:
Originally Posted by ZeeX
Maybe you have changed the order of commands at OnPlayerCommandText? Have you tried to change ALL commands to dcmd and sscanf?
Also you may try this system instead of dcmd, it should decrease your CPU usage.
Just my admin and irc commands were changed, i plan changing all of them if possible.

But it seems that its hard to get it working as smoothe, as it is with strtok.

What i mean is, with strtok, there were some commands i made where they would have more than one result depending on the param used.

Like i made /pcarcolor [color1] [color2]

If the only one used was colour 1, then colour 2 would equal colour 1.

and if colour2 was used, then they would both be used on the vehicle.

Commands like that i found hard in sscanf.
Reply
#5

Thanks y_less, zcmd looks a little confusing for me, but so did sscanf and dcmd at first. I'll look into it and start using it.

As for CPU, there is random spikes sometimes, then it settles down again. I'll add some delays for some commands, with settimerex. Stopping a player spamming or over using certain commands.

I have under OnPlayerUpdate added some code to check a players interior. Could that be a cause of high CPU usage?

Theres only two things in OnPlayerUpdate.

One to stream the object, with kc's streamer. And the second is checking a players interior, and setting them on the same team, so they cant kill eachother.


I've also noticed that IRC commands sometimes cause the server to crash. especially !players right now there are 41 players, and when i do !players in irc, it shows the list of players the crashes the server.

EDIT: Would probably help if i included the code

http://pastebin.com/m2c29a602


31 players, CPU: 25.6%, RAM: 1.3%
Reply
#6

Quote:
Originally Posted by Outbreak
And the second is checking a players interior, and setting them on the same team, so they cant kill eachother.
There is OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid) callback forwarded at a_samp.inc, I think you may use this instead
Reply
#7

Yeah i have made it set the players to the interior team under the callback OnPlayerInteriorChange

Though with a lot of players, sometimes it drifts out of sync, and then players are able to kill eachother in interiors.

So instead of adding a timer i used OnPlayerUpdate.

Would a timer be easier on the CPU or is OnPlayerUpdate fine?
Reply
#8

Its how the streamer was made, it isnt mine...

But i will change it to a timer then. Would 100ms be more efficient than using OnPlayerUpdate??



There is no define for the actual command?

Seems pretty simple..

What about if i wanted to call a command for a player?

i have a command /cmd [playerid] [/command]

Which calls the command as if the player wrote it.


could you look at this?

http://pastebin.com/m2c29a602

And see what could be causing the server to crash when this command is used when there is a lot of players (30 or so) ingame.
Reply
#9

Quote:
Originally Posted by Outbreak
Its how the streamer was made, it isnt mine...

But i will change it to a timer then. Would 100ms be more efficient than using OnPlayerUpdate??



There is no define for the actual command?

Seems pretty simple..

What about if i wanted to call a command for a player?

i have a command /cmd [playerid] [/command]

Which calls the command as if the player wrote it.


could you look at this?

http://pastebin.com/m2c29a602

And see what could be causing the server to crash when this command is used when there is a lot of players (30 or so) ingame.
Yes, changing it to something else rather than OnPlayerUpdate and using a 100ms timer will be about 100 times less pressure on the server. Which is alot!

As for that command. I will look into it also and see what I can find. Maybe Alex will find it faster than me :P

EDIT: I've changed that command a bit for you, not sure if it will fix any crashes but it definately looks better

http://pastebin.com/d7a424a27

Also, thinking about it, its possible that when you have over 30 player it exceeds the max string length of 512 that you have set.
Reply
#10

Hmm i'll try dividing the command into two parts, if the count is 20 or below, to jsut have it used on 1 string, if its 40 or below, have it on two strings, and above goes on 3 strings.

I think it would work, i'll test it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)