Updated the reload and shutdown mecanism to avoid a loop when shutting down from inside the game. Made sure to have server sync correctly with portal at @reload (some session info were lost before). Some other cleanups.

This commit is contained in:
Griatch 2012-05-01 14:19:54 +02:00
parent e82515f8cb
commit 94477b8340
8 changed files with 171 additions and 118 deletions

View file

@ -6,6 +6,7 @@ System commands
import traceback
import os, datetime, time
from sys import getsizeof
import django, twisted
from django.conf import settings
@ -16,9 +17,10 @@ from src.players.models import PlayerDB
from src.utils import logger, utils, gametime, create
from src.commands.default.muxcommand import MuxCommand
# delayed imports
_resource = None
_idmapper = None
_attribute_cache = None
# limit symbol import for API
__all__ = ("CmdReload", "CmdReset", "CmdShutdown", "CmdPy",
@ -537,12 +539,31 @@ class CmdTime(MuxCommand):
class CmdServerLoad(MuxCommand):
"""
server load statistics
server load and memory statistics
Usage:
@serverload
Show server load statistics in a table.
This command shows server load statistics and dynamic memory
usage.
Some Important statistics in the table:
{wServer load{n is an average of processor usage. It's usually
between 0 (no usage) and 1 (100% usage), but may also be
temporarily higher if your computer has multiple CPU cores.
The {wResident/Virtual memory{n displays the total memory used by
the server process.
Evennia {wcaches{n all retrieved database entities when they are
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.
"""
key = "@server"
aliases = ["@serverload", "@serverprocess"]
@ -559,11 +580,13 @@ class CmdServerLoad(MuxCommand):
if not utils.host_os_is('posix'):
string = "Process listings are only available under Linux/Unix."
else:
global _resource, _idmapper
global _resource, _idmapper, _attribute_cache
if not _resource:
import resource as _resource
if not _idmapper:
from src.utils.idmapper import base as _idmapper
if not _attribute_cache:
from src.typeclasses.models import _ATTRIBUTE_CACHE as _attribute_cache
import resource
loadavg = os.getloadavg()
@ -622,10 +645,10 @@ class CmdServerLoad(MuxCommand):
for row in ftable:
string += "\n " + "{w%s{n" % row[0] + "".join(row[1:])
# cache size
# object cache size
cachedict = _idmapper.cache_size()
totcache = cachedict["_total"]
string += "\n{w Object cache usage: %5.2f MB (%i items){n" % (totcache[1], totcache[0])
string += "\n{w Database entity (idmapper) cache usage:{n %5.2f MB (%i items)" % (totcache[1], totcache[0])
sorted_cache = sorted([(key, tup[0], tup[1]) for key, tup in cachedict.items() if key !="_total" and tup[0] > 0],
key=lambda tup: tup[2], reverse=True)
table = [[tup[0] for tup in sorted_cache],
@ -634,6 +657,10 @@ class CmdServerLoad(MuxCommand):
ftable = utils.format_table(table, 5)
for row in ftable:
string += "\n " + row[0] + row[1] + row[2]
# attribute cache
size = sum([sum([getsizeof(obj) for obj in dic.values()]) for dic in _attribute_cache.values()])/1024.0
count = sum([len(dic) for dic in _attribute_cache.values()])
string += "\n{w On-entity Attribute cache usage:{n %5.2f MB (%i items)" % (size, count)
caller.msg(string)
# class CmdPs(MuxCommand):