Raised This Month: $51 Target: $400
 12% 

[TF2] Database Memory Leak


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 11-18-2015 , 22:19   [TF2] Database Memory Leak
Reply With Quote #1

Code:
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, iArg2, iArg3) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218640, 6, 6, 4, 'medic_shield_deployed_destroyed', 'Yanm', 3, 792, 1) ran successfully. (#102)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #134 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218644, 6, 6, 4, 'player_damage', 'Engineer', 15, 'TeamWork OP Volvo Please Nerf', 27, 17, 24, 0, 0) ran successfully. (#134)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #102 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218646, 6, 6, 4, 'player_damage', 'Giant Heal-on-Kill Heavy', 19, 'Hydrogen', 2, 166, 18, 0, 0) ran successfully. (#102)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #102 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218646, 6, 6, 4, 'player_damage', 'Giant Heal-on-Kill Heavy', 19, 'Hydrogen', 2, 166, 18, 0, 0) ran successfully. (#102)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #134 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218649, 6, 6, 4, 'player_damage', 'Giant Heal-on-Kill Heavy', 19, 'Hydrogen', 2, 148, 18, 0, 0) ran successfully. (#134)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #102 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218649, 6, 6, 4, 'player_damage', 'Giant Heal-on-Kill Heavy', 19, 'Hydrogen', 2, 148, 18, 0, 0) ran successfully. (#102)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #102 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218652, 6, 6, 4, 'player_damage', 'Giant Heal-on-Kill Heavy', 19, 'Hydrogen', 2, 130, 18, 0, 0) ran successfully. (#102)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #134 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218652, 6, 6, 4, 'player_damage', 'Giant Heal-on-Kill Heavy', 19, 'Hydrogen', 2, 130, 18, 0, 0) ran successfully. (#134)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #102 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218656, 6, 6, 4, 'player_damage', 'Giant Heal-on-Kill Heavy', 19, 'Yanm', 3, 106, 2, 0, 0) ran successfully. (#102)
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query #102 completed successfully.
L 11/18/2015 - 20:46:40: [mvm_source_tv_feedback.smx] >>>> Query INSERT INTO EventTable (FileName, TimeStamp, Time, Tick, Wave, AttemptedWaves, RoundStatus, EventName, sArg1, iArg1, sArg2, iArg2, iArg3, iArg4, iArg5, iArg6) VALUES ('mvm_mannhattan_advanced1_1447894301', 1447897600, 3299, 218658, 6, 6, 4, 'player_damage', 'Giant Heal-on-Kill Heavy', 19, 'Hydrogen', 2, 52, 18, 0, 0) ran successfully. (#102)
L 11/18/2015 - 20:46:40: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "mvm_source_tv_feedback.smx")
L 11/18/2015 - 20:46:40: [SM] Unloading plugin to free 32487 handles.
L 11/18/2015 - 20:46:40: [SM] Contact the author(s) of this plugin to correct this error.
L 11/18/2015 - 20:46:40: --------------------------------------------------------------------------
L 11/18/2015 - 20:46:40: Type	IDatabase           |	Count	32486
L 11/18/2015 - 20:46:40: Type	Timer               |	Count	1
L 11/18/2015 - 20:46:40: -- Approximately 0 bytes of memory are in use by (32487) Handles.

L 11/18/2015 - 20:46:40: [SM] MEMORY LEAK DETECTED IN PLUGIN (file "mvm_source_tv_feedback.smx")
L 11/18/2015 - 20:46:40: [SM] Unloading plugin to free 32487 handles.
L 11/18/2015 - 20:46:40: [SM] Contact the author(s) of this plugin to correct this error.
L 11/18/2015 - 20:46:40: --------------------------------------------------------------------------
L 11/18/2015 - 20:46:40: Type	IDatabase           |	Count	32486
L 11/18/2015 - 20:46:40: Type	Timer               |	Count	1
L 11/18/2015 - 20:46:40: -- Approximately 0 bytes of memory are in use by (32487) Handles.

[SM] Plugin [TF2] MvM Source TV & Feedback Recorder unloaded successfully.
Completed SourceTV demo "mvm_mannhattan_advanced1_1447894301.dem", recording time 3279.9
The code is basically 20 event hooks like this:

PHP Code:
    HookEvent("player_hurt"OnPlayerTakeDamage);                                // Called when a player takes damage. 
And the callback is like this:

PHP Code:
public Action OnPlayerTakeDamage(Handle EventHandle, const char[] EventNamebool DontBroadcast)
{
    
// Get a lot of information out from this event.
    
int Victim GetClientOfUserId(GetEventInt(EventHandle"userid"));            // Client index of the victim.
    
int Attacker GetClientOfUserId(GetEventInt(EventHandle"attacker"));        // Client index of the attacker. (0 = CONSOLE, like fall damage and environmental hazards)
    
int Health GetEventInt(EventHandle"health");                            // Victim's health remaining.
    
int DamageDone GetEventInt(EventHandle"damageamount");                    // Damage amount done to victim.
    
bool Crit GetEventBool(EventHandle"crit");                                // Is crit damage?
    
bool MiniCrit GetEventBool(EventHandle"minicrit");                        // Is minicrit damage? (If set to 1, crit is set to 1 as well.)
    
    // Get the names of both players:
    
GetClientNameEscaped(VictimPlayer1sizeof(Player1));
    
GetClientNameEscaped(AttackerPlayer2sizeof(Player2));
    
    
// Now insert in everything:
    
PartiallyFormatString(FixedDataStringsizeof(FixedDataString));
    
Format(QueryStringsizeof(QueryString), PLAYER_DAMAGE_EVENT_QUERYFixedDataStringPlayer1VictimPlayer2AttackerHealthDamageDoneCritMiniCrit);        // victim's name, victim's client index, attacker's name, attacker's client index, victim's leftover health, damage done to victim, is crit, is minicrit
    
SQL_TQuery(FeedbackDatabaseNothingQueryString134);    

The callback is:

PHP Code:
public void Nothing(Handle DatabaseHandleHandle QueryHandle, const char[] Errorint QueryCode)
{
    if (!
StrEqual(Error""))    // error string not empty
    
{
#if defined DEBUG
        
PrintToChatAll("SQL Error #%d: %s See console."QueryCodeError);                    // debug
#endif
        
LogError("SQL Error: %s (Query Code: %d)"ErrorQueryCode);
        
LogError("SQL Error: %s (Query Code: %d)"QueryStringQueryCode);
    }
#if defined DEBUG
    
else
    {
        
LogMessage(">>>> Query #%d completed successfully."QueryCode);                            // use this to check what queries have been executed successfully.
        
LogMessage(">>>> Query %s ran successfully. (#%d)"QueryStringQueryCode);
    }
#endif

That's all this plugin is full of. There are no other handles present. There are no transactions. And it leaked. Why did it leak? Doesn't SQL_TQuery close all handles automatically? I'm confused right now. I also did Ctrl + F "Handle " to find handle declarations but there are only 2 unclosed GLOBAL database handles from OnPluginStart and there isn't anything that derives from Handle (methodmap-wise).

Thanks for any help!

Last edited by Potato Uno; 11-18-2015 at 22:22.
Potato Uno is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 11-18-2015 , 23:43   Re: [TF2] Database Memory Leak
Reply With Quote #2

I think I found the problem. SM's sqlite database driver is too weak to handle my plugin, lol.

From repeatedly calling sm_handle_dump 10 times per second and counting the number of database handles, SM's sqlite deals with 300 queries per second whereas my plugin was throwing anywhere near 1000 queries per second. That just stockpiled up and up and up until eventually the backlog hit 30,000 queries and crashed.

A transaction might do a better job, I think.

Last edited by Potato Uno; 11-19-2015 at 15:13.
Potato Uno is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-19-2015 , 16:41   Re: [TF2] Database Memory Leak
Reply With Quote #3

The thoughput limitation on threaded queries is intentional - you should batch your inserts.
__________________
asherkin is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 11-19-2015 , 16:47   Re: [TF2] Database Memory Leak
Reply With Quote #4

Batch inserts as in transactions? (My experience with SQL is heavily limited.)
Potato Uno is offline
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 11-19-2015 , 17:54   Re: [TF2] Database Memory Leak
Reply With Quote #5

This is some serious event logging.
ReFlexPoison is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 11-19-2015 , 19:28   Re: [TF2] Database Memory Leak
Reply With Quote #6

That's what you have to deal with if you're running a mapping community. Log everything you possibly can and then compile it into a useful summary (later on) for mappers to review for any game.

I think transactions is not going to work because I believe it internally creates a query handle per query added to the transaction object. But let's see.
Potato Uno is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 11-19-2015 , 20:10   Re: [TF2] Database Memory Leak
Reply With Quote #7

Transactions + an infinite spinning timer that executes the transaction object every second avoided the crash problem. A dump of sm_dump_handles executed 10 times per second showed that this plugin overall had on average 15 handles active at once, as opposed to 23,000. I think this might be solved, for now.

Last edited by Potato Uno; 11-19-2015 at 23:12.
Potato Uno is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:42.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode