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.
This commit is contained in:
Neil Williams
2012-09-10 17:39:10 -07:00
parent 792c7d5ad5
commit 91c6ab63a8
2 changed files with 17 additions and 2 deletions

View File

@@ -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:

View File

@@ -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)