]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Stop recreating hashmaps every hour, move garbage collection code related to local...
authorattilamolnar <attilamolnar@hush.com>
Thu, 4 Apr 2013 17:23:16 +0000 (19:23 +0200)
committerattilamolnar <attilamolnar@hush.com>
Thu, 4 Apr 2013 17:23:16 +0000 (19:23 +0200)
include/inspircd.h
include/usermanager.h
src/commands/cmd_rehash.cpp
src/inspircd.cpp
src/server.cpp
src/usermanager.cpp

index 099b9dd8766d57887659f7298cca4c0b1bfff8d2..2e1cfbd21307270da775b569151136795c1e715b 100644 (file)
@@ -822,12 +822,6 @@ class CoreExport InspIRCd
         */
        void Cleanup();
 
         */
        void Cleanup();
 
-       /** This copies the user and channel hash_maps into new hash maps.
-        * This frees memory used by the hash_map allocator (which it neglects
-        * to free, most of the time, using tons of ram)
-        */
-       void RehashUsersAndChans();
-
        /** Resets the cached max bans value on all channels.
         * Called by rehash.
         */
        /** Resets the cached max bans value on all channels.
         * Called by rehash.
         */
index 3d7fe88fbb2127240377482d2c9641d3e21e465e..812d8e2f2b77b47b37e133d38b77d5c6f2687dd3 100644 (file)
@@ -70,6 +70,12 @@ class CoreExport UserManager
         */
        clonemap global_clones;
 
         */
        clonemap global_clones;
 
+       /**
+        * Reset the already_sent IDs so we don't wrap it around and drop a message
+        * Also removes all expired invites
+     */
+       void GarbageCollect();
+
        /** Add a client to the system.
         * This will create a new User, insert it into the user_hash,
         * initialize it as not yet registered, and add it to the socket engine.
        /** Add a client to the system.
         * This will create a new User, insert it into the user_hash,
         * initialize it as not yet registered, and add it to the socket engine.
index abf0b7876f88ac78a7a55f7d477908b06b5c3759..1ad96d794b10534e375216bafbb7e4d88a3dbe24 100644 (file)
@@ -88,7 +88,6 @@ CmdResult CommandRehash::Handle (const std::vector<std::string>& parameters, Use
                /* Don't do anything with the logs here -- logs are restarted
                 * after the config thread has completed.
                 */
                /* Don't do anything with the logs here -- logs are restarted
                 * after the config thread has completed.
                 */
-               ServerInstance->RehashUsersAndChans();
                FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
 
 
                FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
 
 
index 9ab7b9dbe526144ea9880e47217fb037bdd20287..c349083788e83977bd6190674cd50b0f800c5779 100644 (file)
@@ -191,41 +191,6 @@ void InspIRCd::ResetMaxBans()
                i->second->ResetMaxBans();
 }
 
                i->second->ResetMaxBans();
 }
 
-/** Because hash_map doesn't free its buckets when we delete items, we occasionally
- * recreate the hash to free them up.
- * We do this by copying the entries from the old hash to a new hash, causing all
- * empty buckets to be weeded out of the hash.
- * Since this is quite expensive, it's not done very often.
- */
-void InspIRCd::RehashUsersAndChans()
-{
-       user_hash* old_users = Users->clientlist;
-       Users->clientlist = new user_hash;
-       for (user_hash::const_iterator n = old_users->begin(); n != old_users->end(); n++)
-               Users->clientlist->insert(*n);
-       delete old_users;
-
-       user_hash* old_uuid = Users->uuidlist;
-       Users->uuidlist = new user_hash;
-       for (user_hash::const_iterator n = old_uuid->begin(); n != old_uuid->end(); n++)
-               Users->uuidlist->insert(*n);
-       delete old_uuid;
-
-       chan_hash* old_chans = chanlist;
-       chanlist = new chan_hash;
-       for (chan_hash::const_iterator n = old_chans->begin(); n != old_chans->end(); n++)
-               chanlist->insert(*n);
-       delete old_chans;
-
-       // Reset the already_sent IDs so we don't wrap it around and drop a message
-       LocalUser::already_sent_id = 0;
-       for (LocalUserList::const_iterator i = Users->local_users.begin(); i != Users->local_users.end(); i++)
-       {
-               (**i).already_sent = 0;
-               (**i).RemoveExpiredInvites();
-       }
-}
-
 void InspIRCd::SetSignals()
 {
 #ifndef _WIN32
 void InspIRCd::SetSignals()
 {
 #ifndef _WIN32
@@ -818,7 +783,7 @@ int InspIRCd::Run()
 
                        if ((TIME.tv_sec % 3600) == 0)
                        {
 
                        if ((TIME.tv_sec % 3600) == 0)
                        {
-                               this->RehashUsersAndChans();
+                               Users->GarbageCollect();
                                FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
                        }
 
                                FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
                        }
 
index 4741f942d53d2b5e838ddf52f1f16f5a435aeb92..691ab3842f7d1c455d06577fcb90d9b40cbfcff2 100644 (file)
@@ -59,7 +59,6 @@ void InspIRCd::Exit(int status)
 void RehashHandler::Call(const std::string &reason)
 {
        ServerInstance->SNO->WriteToSnoMask('a', "Rehashing config file %s %s",ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()), reason.c_str());
 void RehashHandler::Call(const std::string &reason)
 {
        ServerInstance->SNO->WriteToSnoMask('a', "Rehashing config file %s %s",ServerConfig::CleanFilename(ServerInstance->ConfigFileName.c_str()), reason.c_str());
-       ServerInstance->RehashUsersAndChans();
        FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
        if (!ServerInstance->ConfigThread)
        {
        FOREACH_MOD(I_OnGarbageCollect, OnGarbageCollect());
        if (!ServerInstance->ConfigThread)
        {
index 58cbb7e5b3877e738958108585f750933d947379..2d9c3f281c3953aeb2ad29119e7826c2158c7e0f 100644 (file)
@@ -389,3 +389,14 @@ int UserManager::ModeCount(const char mode)
        }
        return c;
 }
        }
        return c;
 }
+
+void UserManager::GarbageCollect()
+{
+       // Reset the already_sent IDs so we don't wrap it around and drop a message
+       LocalUser::already_sent_id = 0;
+       for (LocalUserList::const_iterator i = this->local_users.begin(); i != this->local_users.end(); i++)
+       {
+               (**i).already_sent = 0;
+               (**i).RemoveExpiredInvites();
+       }
+}