15.08.2014, 12:21
Hello everyone,
My SA:MP server has some extreme memory leakage problems. I've been trying to fix it for months, but at some point I simply gave up because I couldn't figure out what was causing it. But then I realized that maybe someone on the forums can help me with this.
In this thread I'll try to post as much information as I have, including what I've tried to fix the problem myself.
The problem:
Since mid-January I've moved my SA:MP server from Volt-Host to SmartBytesHosting due to the many problems I've experienced with Volt-Host in the past. Before the migration of the server to the new hosting I don't recall there ever being any memory related issues with my script or server, but I can't confirm this for 100% because an uptime longer than a few days was impossible with Volt-Host.
After the hosting company migration it quickly came to my attention that my server would automatically restart every week or so. A quick discussion with the owner of the new hosting company taught me that this happened due to the high memory usage. SmartBytesHosting runs some sort of script that protects their services from getting disrupted by their customers' scripts eating up too much memory or CPU cycles.
The memory leakage causes unwanted server down time (due to the reboots) and it overloads the servers of SmartBytesHosting, so that's obviously a problem.
The first thing I could come up with was the fact that both hosting companies are using a different server operating system. Volt-Host uses CentOS (a Linux distro) and SmartBytesHosting uses Windows Server. This is actually the only obvious difference between now and before.
This is the graph that shows the RAM usage of the past 30 days:
(The dips are the server restarts)
Information about my server:
The SA:MP server in question uses the following default SA:MP filterscripts:
The gamemode:
My gamemode is heavily based on the MySQL plugin. It uses the database to store the player accounts, achievements, sessions, businesses, houses, stores, races, settings and a few other things. This is why I’ve looked into all the MySQL related scripts first.
I’ve checked whether I’ve forgotten to clear the query results throughout the entire script, verified that all queries were correct (by checking the log files for errors) and searched the script for any obvious mistakes related to this.
There were indeed a few missing mysql_free_result() calls here and there, and one query failed to execute with some players due to the string being cut, but after fixing that I didn’t notice any difference with memory consumption.
Besides the MySQL parts I didn’t know what else to look for inside the gamemode.
Reproducing the high memory usage:
The biggest problem with attempting to diagnose and fix this issue is the fact that I was unable to reproduce the memory leak locally.
Setting up a local copy of the server, both using Linux and Windows, and letting it run unattended for about a month did nothing whatsoever. Staying connected and messing around in-game, trying to execute as many MySQL queries as I can did nothing whatsoever. Creating a script to make my computer rejoin the server constantly did nothing, trying to do the same thing with a few people did nothing…
The only thing that I couldn’t do locally that is possible on the main server was to get around ~20 players to remain connected and play ‘normally’. Because of this, I don’t know the ‘key’ to solving the problem.
Wrapping up this forum post:
I know that this was a somewhat long post, so I apologize if it’s a bit boring to read. I did my best to keep it as short as possible without leaving out any crucial information.
If anyone knows what might cause this, knows what I can try to solve this or have any other general tips that may help me to fix this issue then I’d love to know them! All help is appreciated a lot!
Yoshi
My SA:MP server has some extreme memory leakage problems. I've been trying to fix it for months, but at some point I simply gave up because I couldn't figure out what was causing it. But then I realized that maybe someone on the forums can help me with this.
In this thread I'll try to post as much information as I have, including what I've tried to fix the problem myself.
The problem:
Since mid-January I've moved my SA:MP server from Volt-Host to SmartBytesHosting due to the many problems I've experienced with Volt-Host in the past. Before the migration of the server to the new hosting I don't recall there ever being any memory related issues with my script or server, but I can't confirm this for 100% because an uptime longer than a few days was impossible with Volt-Host.
After the hosting company migration it quickly came to my attention that my server would automatically restart every week or so. A quick discussion with the owner of the new hosting company taught me that this happened due to the high memory usage. SmartBytesHosting runs some sort of script that protects their services from getting disrupted by their customers' scripts eating up too much memory or CPU cycles.
The memory leakage causes unwanted server down time (due to the reboots) and it overloads the servers of SmartBytesHosting, so that's obviously a problem.
The first thing I could come up with was the fact that both hosting companies are using a different server operating system. Volt-Host uses CentOS (a Linux distro) and SmartBytesHosting uses Windows Server. This is actually the only obvious difference between now and before.
This is the graph that shows the RAM usage of the past 30 days:
(The dips are the server restarts)
Information about my server:
The SA:MP server in question uses the following default SA:MP filterscripts:
- ferriswheel.amx
- ls_elevator.amx
- StrickenKid’s MySQL plugin
- Incognito’s object streamer
- Incognito’s IRC plugin
- ******’ sscanf plugin
- Fro1sha’s regular expressions
- Crash detect
The gamemode:
My gamemode is heavily based on the MySQL plugin. It uses the database to store the player accounts, achievements, sessions, businesses, houses, stores, races, settings and a few other things. This is why I’ve looked into all the MySQL related scripts first.
I’ve checked whether I’ve forgotten to clear the query results throughout the entire script, verified that all queries were correct (by checking the log files for errors) and searched the script for any obvious mistakes related to this.
There were indeed a few missing mysql_free_result() calls here and there, and one query failed to execute with some players due to the string being cut, but after fixing that I didn’t notice any difference with memory consumption.
Besides the MySQL parts I didn’t know what else to look for inside the gamemode.
Reproducing the high memory usage:
The biggest problem with attempting to diagnose and fix this issue is the fact that I was unable to reproduce the memory leak locally.
Setting up a local copy of the server, both using Linux and Windows, and letting it run unattended for about a month did nothing whatsoever. Staying connected and messing around in-game, trying to execute as many MySQL queries as I can did nothing whatsoever. Creating a script to make my computer rejoin the server constantly did nothing, trying to do the same thing with a few people did nothing…
The only thing that I couldn’t do locally that is possible on the main server was to get around ~20 players to remain connected and play ‘normally’. Because of this, I don’t know the ‘key’ to solving the problem.
Wrapping up this forum post:
I know that this was a somewhat long post, so I apologize if it’s a bit boring to read. I did my best to keep it as short as possible without leaving out any crucial information.
If anyone knows what might cause this, knows what I can try to solve this or have any other general tips that may help me to fix this issue then I’d love to know them! All help is appreciated a lot!
Yoshi