SphereCommunity
Sever goes unstable and crashes - Printable Version

+- SphereCommunity (https://forum.spherecommunity.net)
+-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d)
+--- Forum: Script Help (/Forum-Script-Help)
+--- Thread: Sever goes unstable and crashes (/Thread-Sever-goes-unstable-and-crashes)



Sever goes unstable and crashes - Ankron - 01-25-2015 06:14 PM

I'm not sure why the server goes unstable and crashes, I can't see anything in the script that would cause the crash... Do you guys see anything?

AreaSpawner V0.1A


RE: Sever goes unstable and crashes - XuN - 01-25-2015 06:20 PM

Added [spoiler] and [code] to your post, anyway it seems cutted... use http://www.pastebin.com for big pastes, the thread will load faster and we can read it better than here.


RE: Sever goes unstable and crashes - Ankron - 01-25-2015 06:40 PM

Ok, I put it in pastebin and updated the original post.


RE: Sever goes unstable and crashes - XuN - 01-25-2015 07:32 PM

The passable function is really INSANE, it have up to 8k lines depending on the arg given!! hence up to 4k checks.

As I can see you are checking the Terrains to see if you can walk upon them or not, right? what about selecting terrain types using serv.map(x,y,z).type instead of .terrain and discarding the ones you don't want? something like ...

Code:
local.terrain=<serv.map(<eval <local.x>>,<eval <local.y>>,<argv4>).type>
local.passable=<qval (<local.terrain>==t_water || <local.terrain>==t_rock || <local.terrain>==t_lava) ?0:1>
You can add more checks there, even create new terrain types just to create a 'direct' check instead of 4k of them.

I would even better suggest you to create one definition per valid terrain, something like:

Code:
[defname valid_Terrains]
terrain_valid_1=1
terrain_valid_2=1
...
terrain_valid_22=1
...
terrain_valid_16383=1

and checking it via

Code:
local.passable=<def0.terrain_valid_<serv.map(<eval <local.x>>,<eval <local.y>>,<argv4>).terrain>>

rather than using that big one function (but I prefer the first option).


RE: Sever goes unstable and crashes - Coruja - 01-26-2015 03:09 AM

probably your function is making the server unstable because you're executing too much SQL commands
everytime you execute a SQL command, sphere will freeze until the SQL server return back the SQL response to sphere. On lightweight SQL functions, you won't notice any freeze because it will execute the function in just 0.1s. But if you execute 100x this same SQL command on loop, the total execution time will be increase to 10s (100 x 0.1s) and this will freeze sphere for about 10 seconds until all SQL commands got executed

so unfortunately to fix this you must rewrite your code to make it use less SQL commands

also you can optimize a lot this passable function, reducing 48478647864763874 lines to just a few lines
instead check for every single value, you can check an entire value range on just a single line

this:
Code:
[function passable]
if <argv0>==3
        return 1
elseif <argv0>==4
        return 1
elseif <argv0>==5
        return 1
elseif <argv0>==6
        return 1
elseif <argv0>==7
        return 1
elseif <argv0>==8
        return 1
elseif <argv0>==9
        return 1
elseif <argv0>==10
        return 1
elseif <argv0>==11
        return 1
elseif <argv0>==12
        return 1
elseif <argv0>==13
        return 1
elseif <argv0>==14
        return 1
elseif <argv0>==15
        return 1
elseif <argv0>==16
        return 1
elseif <argv0>==17
        return 1
elseif <argv0>==18
        return 1
elseif <argv0>==19
        return 1
elseif <argv0>==20
        return 1
elseif <argv0>==21
        return 1
elseif <argv0>==22
        return 1
elseif <argv0>==23
        return 1
elseif <argv0>==24
        return 1
elseif <argv0>==25
        return 1
elseif <argv0>==51
        return 1
elseif <argv0>==52
        return 1
elseif <argv0>==53
        return 1
elseif <argv0>==54
        return 1
elseif <argv0>==55
        return 1
elseif <argv0>==56
        return 1
elseif <argv0>==57
        return 1
elseif <argv0>==58
        return 1
elseif <argv0>==59
        return 1
elseif <argv0>==60
        return 1
elseif <argv0>==61
        return 1
elseif <argv0>==62
        return 1
...

can be reduced to:
Code:
[function passable]
if (<argv0> >= 3) && (<argv0> <= 25)
        return 1
elseif (<argv0> >= 51) && (<argv0> <= 62)
        return 1
...



RE: Sever goes unstable and crashes - Extreme - 01-26-2015 05:37 AM

HOOOOOOOOLY SHIT!
This is the biggest function I saw in my life.
But really, kinda funny. I hope you didn't write this yourself. lol

And yes, use first code that XuN wrote.


RE: Sever goes unstable and crashes - Ankron - 01-26-2015 07:57 AM

Na, every script has a process of debugging and making more efficient. It works, problem is it shuts down. Maybe I need to find a way to load/unload all the spawn data when the player enters/exits the region.


RE: Sever goes unstable and crashes - XuN - 01-27-2015 01:10 AM

It shuts down because, as Coruja said, Sphere waits for SQL execution so it hangs in the proccess. I gave you alternatives to this function without knowledge of what you want so if they are not good enough you may expose here what do you want so we can help you out.


RE: Sever goes unstable and crashes - Ankron - 01-27-2015 05:32 AM

Yep, I've since divided each sql statement into it's own tick, it's stabilized the server. Big Grin Thanks guys.[/align]