Skip to content

Instantly share code, notes, and snippets.

View GrahamDumpleton's full-sized avatar
😎

Graham Dumpleton GrahamDumpleton

😎
View GitHub Profile
@GrahamDumpleton
GrahamDumpleton / gist:3392348
Created August 19, 2012 05:50
Brute force way of detecting memory growth in Django.
import os
import psutil
import sys
THRESHOLD = 2*1024*1024
class MemoryUsageMiddleware(object):
def process_request(self, request):
request._mem = psutil.Process(os.getpid()).get_memory_info()
@GrahamDumpleton
GrahamDumpleton / gist:3309485
Created August 10, 2012 00:24
Name transaction using in_function.
def _name_transaction(self, f, *args):
transaction = newrelic.api.transaction.current_transaction()
if transaction:
name = newrelic.api.object_wrapper.callable_name(f)
transaction.name_transaction(name)
newrelic.api.in_function.wrap_in_function(module, 'application._delegate',
_name_transaction)
@GrahamDumpleton
GrahamDumpleton / gist:3303627
Created August 9, 2012 12:02
Application of of resin adjust.
w,h = new_img.size
for x in range(0, w):
adjuster = ResinAdjust()
for y in range(0, h):
p = new_img.getpixel((x, y))
new_p = adjuster(p)
new_img.putpixel((x, y), new_p)
@GrahamDumpleton
GrahamDumpleton / gist:3303610
Created August 9, 2012 11:59
Resin adjust with extended history.
class ResinAdjust(object):
def __init__(self):
self._lastBlack = 0
self._lastWhite = 1
def __call__(self, value):
value = min(value, 180)
if self._lastBlack:
@GrahamDumpleton
GrahamDumpleton / gist:3225782
Created August 1, 2012 10:56
Sample of agent configuration of instrumenting pycassa.
# This would go in the existing [newrelic] section of agent configuration file.
# There should already be a empty setting in sample configuration file.
transaction_tracer.function_trace = pycassa.columnfamily:ColumnFamily.xget
pycassa.columnfamily:ColumnFamily.get
pycassa.columnfamily:ColumnFamily.get_indexed_slices
pycassa.columnfamily:ColumnFamily.multiget
... add other methods
pycassa.columnfamilymap:ColumnFamilyMap.combine_columns
pycassa.columnfamilymap:ColumnFamilyMap.get
@GrahamDumpleton
GrahamDumpleton / gist:3153982
Created July 21, 2012 00:19
Force gevent monkey patching.
#!/usr/bin/env python
from gevent import monkey
monkey.patch_all()
import os
os.environ['GEVENT_NOPATCH'] = '1'
import newrelic.agent
newrelic.agent.initialize('/srv/socialcode/project/socialcode/newrelic.ini')
@GrahamDumpleton
GrahamDumpleton / gist:3139309
Created July 18, 2012 22:21
Test that RUM header/footer are being output.
import newrelic.agent
newrelic.agent.register_application(timeout=10.0)
def start_response(status, headers): pass
@newrelic.api.web_transaction.wsgi_application()
def handler(environ, start_response):
status = '200 OK'
output = 'Hello World!'