Skip to content

Instantly share code, notes, and snippets.

import re, sys, os
from datetime import datetime
from collections import defaultdict
class Request():
def __init__(self, id, start):
self.id = id
self.start = start
from gevent import http
import psyco_gevent
psyco_gevent.make_psycopg_green()
from psycopg2.pool import SimpleConnectionPool
dsn = 'dbname=test host=127.0.0.1 port=5433 user=test password=123'
dbpool = SimpleConnectionPool(10,15,dsn)
def handler(request):
if request.uri.startswith('/recall/'):
@def
def / bench.py
Created December 16, 2011 08:34
np.savez vs pickle
import cPickle as pickle
import numpy as np
import StringIO
import time
import zlib
a = np.array(range(100000))
b = np.array(range(200000, 300000))
file_obj = StringIO.StringIO()
start = time.time()
@def
def / output
Created January 27, 2012 11:38
cPickle vs cPickle+HIGHEST_PROTOCOL vs marshal
cPickle default dumps: 0.107237100601
cPickle HIGHEST_PROTOCOL dumps: 0.0678668022156
marshal dumps: 0.0203359127045
cPickle default loads: 0.0411729812622
cPickle HIGHEST_PROTOCOL loads: 0.0352649688721
marshal loads: 0.0221829414368
@def
def / output
Created January 27, 2012 12:20
base64 vs binascii
marshal dumps: 0.0218579769135
marshal dumps with base64: 0.0708141326904
marshal dumps with binascii: 0.0610530376434
marshal loads: 0.0211379528046
marshal loads with base64: 0.0429949760437
marshal loads with base64: 0.0391380786896
@def
def / serialize.py
Created February 23, 2012 11:31
serialize
def load_obj(data):
try:
return cPickle.loads(zlib.decompress(data))
except zlib.error:
return cPickle.loads(data)
def dump_obj(obj):
# In [24]: %timeit zlib.compress(cPickle.dumps(a, protocol=cPickle.HIGHEST_PROTOCOL), 1)
# 1000 loops, best of 3: 1.74 ms per loop
@def
def / t.py
Created September 25, 2013 10:25
import multiprocessing
import time
a, b = multiprocessing.Pipe()
def func(conn):
while True:
conn.recv()
p = multiprocessing.Process(target=func, args=(b,))
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp
spec:
selector:
matchLabels:
app: webapp
replicas: 2
template: