From 91c6ab63a8de9a6dd6169bc8d4beaf996d324aec Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Mon, 10 Sep 2012 17:39:10 -0700 Subject: [PATCH] Locks: Pare down the traceback stored in the lock cache. This reduces the size of the traceback data stored in the lock caches by an order of magnitude. It is intended to help with the drastic imbalance in lock cache network usage. --- r2/r2/lib/lock.py | 5 +++-- r2/r2/lib/utils/utils.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/r2/r2/lib/lock.py b/r2/r2/lib/lock.py index dabf812b4..8b07b4180 100644 --- a/r2/r2/lib/lock.py +++ b/r2/r2/lib/lock.py @@ -24,10 +24,11 @@ from __future__ import with_statement from time import sleep from datetime import datetime from threading import local -from traceback import format_stack import os import socket +from r2.lib.utils import simple_traceback + # thread-local storage for detection of recursive locks locks = local() @@ -58,7 +59,7 @@ class MemcacheLock(object): def __enter__(self): start = datetime.now() - my_info = (reddit_host, reddit_pid, ''.join(format_stack())) + my_info = (reddit_host, reddit_pid, simple_traceback()) #if this thread already has this lock, move on if self.key in self.locks: diff --git a/r2/r2/lib/utils/utils.py b/r2/r2/lib/utils/utils.py index b9ba1a5f3..dd4daffe4 100644 --- a/r2/r2/lib/utils/utils.py +++ b/r2/r2/lib/utils/utils.py @@ -20,7 +20,9 @@ # Inc. All Rights Reserved. ############################################################################### +import os import base64 +import traceback from urllib import unquote_plus from urllib2 import urlopen @@ -1426,3 +1428,15 @@ def parse_http_basic(authorization_header): except TypeError: raise RequirementException return require_split(auth_data, 2, ":") + + +def simple_traceback(): + """Generate a pared-down traceback that's human readable but small.""" + + stack_trace = traceback.extract_stack(limit=7)[:-2] + return "\n".join(":".join((os.path.basename(filename), + function_name, + str(line_number), + )) + for filename, line_number, function_name, text + in stack_trace)