From 4b8ed234fd7cd99929862b3b4698e649902c2055 Mon Sep 17 00:00:00 2001 From: Griatch Date: Thu, 15 May 2014 23:08:21 +0200 Subject: [PATCH] Added /flushmem switch to the server command to incur the idmapper flushing. --- src/commands/default/system.py | 16 ++++++++++++---- src/scripts/scripthandler.py | 7 +++++++ src/utils/idmapper/base.py | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/commands/default/system.py b/src/commands/default/system.py index c79d68b6c1..9c0516ab3f 100644 --- a/src/commands/default/system.py +++ b/src/commands/default/system.py @@ -624,9 +624,11 @@ class CmdServerLoad(MuxCommand): Switch: mem - return only a string of the current memory usage + flushmem - flush the idmapper cache This command shows server load statistics and dynamic memory - usage. + usage. It also allows to flush the cache of accessed database + objects. Some Important statistics in the table: @@ -641,9 +643,12 @@ class CmdServerLoad(MuxCommand): loaded by use of the idmapper functionality. This allows Evennia to maintain the same instances of an entity and allowing non-persistent storage schemes. The total amount of cached objects - are displayed plus a breakdown of database object types. Finally, - {wAttributes{n are cached on-demand for speed. The total amount of - memory used for this type of cache is also displayed. + are displayed plus a breakdown of database object types. + + The {wflushmem{n switch allows to flush the object cache. Please + note that due to how Python's memory management works, releasing + caches may not show you a lower Residual/Virtual memory footprint, + the released memory will instead be re-used by the program. """ key = "@server" @@ -681,6 +686,9 @@ class CmdServerLoad(MuxCommand): if "mem" in self.switches: caller.msg("Memory usage: RMEM: {w%g{n MB (%g%%), VMEM (res+swap+cache): {w%g{n MB." % (rmem, pmem, vmem)) return + if "flushmem" in self.switches: + caller.msg("Flushed object idmapper cache. Python garbage collector recovered memory from %i objects." % _idmapper.flush_cache()) + return # load table loadtable = prettytable.PrettyTable(["property", "statistic"]) diff --git a/src/scripts/scripthandler.py b/src/scripts/scripthandler.py index b14ad89988..796d9564ea 100644 --- a/src/scripts/scripthandler.py +++ b/src/scripts/scripthandler.py @@ -81,6 +81,13 @@ class ScriptHandler(object): num += script.start() return num + def get(self, scriptid): + """ + Return one or all scripts on this object matching scriptid. Will return + a list. + """ + return ScriptDB.objects.get_all_scripts_on_obj(self.obj, key=scriptid) + def delete(self, scriptid=None): """ Forcibly delete a script from this object. diff --git a/src/utils/idmapper/base.py b/src/utils/idmapper/base.py index cae83e6992..c0611aaf6a 100755 --- a/src/utils/idmapper/base.py +++ b/src/utils/idmapper/base.py @@ -326,7 +326,7 @@ def flush_cache(**kwargs): for cls in class_hierarchy([SharedMemoryModel]): cls.flush_instance_cache() # run the python garbage collector - gc.collect() + return gc.collect() #request_finished.connect(flush_cache) post_syncdb.connect(flush_cache)