SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Discussion (https://forum.sa-mp.com/forumdisplay.php?f=84)
-   -   Profiler result's -Optimization mode (https://forum.sa-mp.com/showthread.php?t=650448)

GospodinX 28/02/2018 11:21 AM

Profiler result's -Optimization mode
 
1 Attachment(s)
I want to optimize my gamemode and I need some help.I'm put profiler plugin on my server from 01:00 to 11:23 today,so i'm get results.

So there are picture who don't want to download:
https://i.imgur.com/dYcv4Fd.png

So if you can tell me what i need to opimize,because i'm not sure what i need to look on this profiler results.For example i don't understand this:

Quote:

operator>=(Float:,Float:) 1515576 6.83%
operator>(Float:,Float:) 1281151 3.33%

Is this much?
Quote:

floatcmp 13220491 3.75%
I use floatcmp just in one line in my mode.For afk check

Short code:

Code:

function AFKCheck(playerid)
{
        GetPlayerPos(playerid, PlayerCurrentPos[playerid][0], PlayerCurrentPos[playerid][1], PlayerCurrentPos[playerid][2]);
        if(!floatcmp(PlayerCurrentPos[playerid][0], PlayerLastPos[playerid][LastX]) && !floatcmp(PlayerCurrentPos[playerid][1], PlayerLastPos[playerid][LastY]))
        {
                PovecajPVarInt(playerid, "PlayerAFK", 1);
        }
        else
        {
                SetPVarInt(playerid, "PlayerAFK", 0);
                  AFK[playerid] = false;
        }
        PlayerLastPos[playerid][LastX] = PlayerCurrentPos[playerid][0];
        PlayerLastPos[playerid][LastY] = PlayerCurrentPos[playerid][1];
        PlayerLastPos[playerid][LastZ] = PlayerCurrentPos[playerid][2];

        if(GetPVarInt(playerid, "PlayerAFK") >= 20)
        {
          //kick(afk 20 minute)
        }
      return 1;
}


Quote:

GetSpeed 790181 8.17%
This function I use in OnPlayerUpdate( if(GetSpeed > 299) kick

Code:

GetSpeed(playerid)
{
    new Float:ST[4];
    if(IsPlayerInAnyVehicle(playerid))
    GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
    else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
    ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 178.8617875;
    return floatround(ST[3]);
}

I'm upload full .html file in attachmens.Thank you

Y_Less 28/02/2018 01:52 PM

Re: Profiler result's -Optimization mode
 
This is a brilliant question on how to actually do something properly, so I'm going to try go in to some depth:

1) From your results there do not appear to be any stand-out sore points. So my first question is - are you sure you need to optimise? That is an exercise for when your mode is performing very poorly and you are getting noticeable problems. Otherwise, the best way you can improve efficiency is by optimising your time and doing something else.

2) Posting an image is no use - you can't sort or inspect that.

3) As a general rule, ignore native functions and operators; there isn't much you can do about them and they are probably all from libraries. They also tend to be the things that are doing the work for your mode, so removing them is actually removing features from your game. We want to optimise when they are called, not get rid of them.

This leaves us with 3 main columns for the rest of the functions - `Calls`, `Self Time`, and `Total Time`. `Total Time` is how long a function took, including the time taken by the functions it called. `Self Time` is the time spent just in that bit of code. Improving the code in that function will bring the `Self Time` down, removing calls to other functions will bring the `Total Time` down.

Calls is very important for knowing where to spend your effort. The slowest functions in that code are functions called in `OnGameModeInit`; however, they are only called once or twice. Given that, once your mode has started optimising them is not going to make any difference - the percentage of time spent in those functions, relative to the total running time of the server, is tiny.

So let's order by `Self Time %`:

publicOnPlayerUpdate124852628.62%19.20.01.033.39%55.20.01.1

28.62% of all your execution time is spent in that just one function. Granted it is called a lot (it is the highest function for number of calls after natives and operators). `FC_OnPlayerUpdate` is second with 9.73%, so they combine to have over 1/3 of `Total Time`.

I've not seen your code, but from that I'm guessing that `OnPlayerUpdate` is a very big function on its own. This is bad for two reasons. 1) Long functions in general are not a good idea, split it up in to small, isolated, testable parts (which can then be profiled separately to find which little piece is the worst). 2) Common wisdom has always been to keep `OnPlayerUpdate` very short - there is very little that must be done there that can't be done less frequently in timers.

GospodinX 28/02/2018 02:13 PM

Re: Profiler result's -Optimization mode
 
First I need to say that my English is not very good,so i hope you will understand me.

1. I had some problems when i had 250+ players(for example my IC Chat is became global chat and also it was start lagg little) ->This is RP server so..I don't use Global Chat) So i'm sure that i need some optimization.Also I need to say that i don't have often a large number of players,so i don't have chance now to turn on profiler with 250+ players(I had it on celebration two years of server so there was many visitors and friends which are not our active players.)

This profiler is turn on midnight(In my time) so we don't have many players at that time .I will post tonight results also.

2.Maybe you are not see,but i'm post full .html file in attachment's.


3.I will look on OnPlayerUpdate,i have GetSpeed check,AntiChaet for Weapons and some check which I can transfer on second timer,it will be better,i think.

FC_OnPlayerUpdate is from include "fuckcleo.inc"
https://pastebin.com/AVrySvAH

So I'm not sure about it.

Thank you very much on answer!

Y_Less 28/02/2018 02:25 PM

Re: Profiler result's -Optimization mode
 
I did see the HTML and downloaded it, I just mentioned the image anyway. Unfortunately, if your problem is with lots of players, a profiler result from very few players is unlikely to be representative of the problems and won't help you identify them.

AmigaBlizzard 08/06/2018 07:36 PM

Re: Profiler result's -Optimization mode
 
I can get why you want to kick cheaters fast, but using OnPlayerUpdate is overkill.
This callback is called at least 30 times per second FOR EVERY PLAYER.
If you have 250 players online, you're executing OnPlayerUpdate 7500 times or more every second.

It won't hurt your server when you just transfer all that code to a 1-second timer.
Then that code runs 250 times per second, which is more than enough.

Optimization starts with clearing OnPlayerUpdate.
I never used that callback and I never will, because I can see no reason for any code that needs to run 30 times per second.

If someone cheats with a speed hack, kicking him within 30ms or 1 second won't make any difference, the cheater will be kicked before he can do more damage anyways.
He won't do that much extra damage in 1 second.

Logic_ 08/06/2018 10:25 PM

Re: Profiler result's -Optimization mode
 
Quote:

Originally Posted by AmigaBlizzard (Post 4027081)
I can get why you want to kick cheaters fast, but using OnPlayerUpdate is overkill.
This callback is called at least 30 times per second FOR EVERY PLAYER.
If you have 250 players online, you're executing OnPlayerUpdate 7500 times or more every second.

It won't hurt your server when you just transfer all that code to a 1-second timer.
Then that code runs 250 times per second, which is more than enough.

Using OnPlayerUpdate as a timer is not an overkill but, a very big mistake.
I've kept my anti cheat timer to call every 1.5~2 seconds.

So for say, my timer will call 2 times in 3 seconds instead of 3. It may not make a very big difference, so why put unnecessary load?

Quote:

Originally Posted by AmigaBlizzard (Post 4027081)
Optimization starts with clearing OnPlayerUpdate.
I never used that callback and I never will, because I can see no reason for any code that needs to run 30 times per second.

The only reason why anyone will use it is when they're making an Anti AFK system, since OnPlayerUpdate is not called when they are paused.

---

@OP: You can also use GetServerTickRate when you've lots of players in the daytime and let us know of the result.

PHP Code:

CMD:tickrate(playerid)
{
    new 
str[25];
    
format(strsizeof str"Server tickrate: %d."GetServerTickRate());
    
SendClientMessage(playeridCOLOR_GREYstr);
    return 
1;



GospodinX 21/10/2018 04:34 PM

Re: Profiler result's -Optimization mode
 
Hi guys,

I need help with optimization one my function which is very bad.This function need to count number of seconds of started event.(It shows for all players in game how much is passed seconds from the starting event)

When I start event:
Code:

        EventCount = GetTickCount();
        UpdateEvent();
        eventtimer = SetTimer("UpdateEvent",990,true);

Code:

forward UpdateEvent();
public UpdateEvent()
{
        new rTime[3];
        new string[10];
          new TimeStamp,TotalEventTime;
          TimeStamp = GetTickCount();
          TotalEventTime = TimeStamp - EventCount;
          ConvertTime(var, TotalRaceTime, rTime[0], rTime[1], rTime[2]);
          format(string, sizeof string, "%02d:%02d",rTime[0], rTime[1]);
          TextDrawSetString(TDEvent, string);
}

ConvertTime(used in UpdateEvent)
Code:

#define ConvertTime(%0,%1,%2,%3,%4) \
        new \
            Float: %0 = floatdiv(%1, 60000) \
        ;\
        %2 = floatround(%0, floatround_tozero); \
        %3 = floatround(floatmul(%0 - %2, 60), floatround_tozero); \
        %4 = floatround(floatmul(floatmul(%0 - %2, 60) - %3, 1000), floatround_tozero)


Profiler result for this function:
https://i.imgur.com/ODIP6b3.png
This is 4. worst function in my mode,so I want to optimize this.Maybe someone have better idea for counting number of seconds?Thanks

Y_Less 21/10/2018 07:32 PM

Re: Profiler result's -Optimization mode
 
OK, that's very odd, but I think the issue here is just the number of times it gets called. There's really not much you can do to that function (except stop using arrays for normal variables, but that's a general rule everywhere). Functions called a lot will have a lot of execution time in them, simply because they are called so often, but honestly for the amount it gets called it looks fine.

GospodinX 21/10/2018 08:02 PM

Re: Profiler result's -Optimization mode
 
Ohh.
This is one-second timer,so If I convert number of calls into hours i will get: 1175 hours .
1175 hours to days = 48 days(but my mode is started only 2 days with profiler)
It's not possible. So I have mistake in mode(I have stoptimer,but maybe some time it doesn't stop.) I will test it.

2)
Quote:

except stop using arrays for normal variables, but that's a general rule everywhere
You think that I should use:
Code:

new rTime1,rTime2,rTime3 ;
instead
Code:

new rTime[3];

Y_Less 21/10/2018 08:51 PM

Re: Profiler result's -Optimization mode
 
OK, yes that sounds like the timer is not being killed correctly. Actually, are you using any sort of timer fix plugin? They are notoriously inaccurate and have been known to randomly accelerate.


All times are GMT. The time now is 07:35 AM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.