Skip to content

Instantly share code, notes, and snippets.

View ajdavis's full-sized avatar

A. Jesse Jiryu Davis ajdavis

View GitHub Profile
Thu Feb 9 15:21:26 [conn60] command admin.$cmd command: { applyOps: [ { ts: Timestamp 1328818874000|1, h: -823979429724744787, op: "i", ns: "test.test", o: { _id: ObjectId('4f342abab09cc797e9f6ce89') } } ] } ntoreturn:1 reslen:50 0ms
PRIMARY> use local
switched to db local
PRIMARY> db.oplog.rs.find()
{ "ts" : { "t" : 1328818308000, "i" : 1 }, "h" : NumberLong(0), "op" : "n", "ns" : "", "o" : { "msg" : "initiating set" } }
{ "ts" : { "t" : 1328818529000, "i" : 1 }, "h" : NumberLong("4789225745807310865"), "op" : "i", "ns" : "test.test", "o" : { "_id" : ObjectId("4f33f724b09cc797e9f6ce87") } }
{ "ts" : { "t" : 1328818541000, "i" : 1 }, "h" : NumberLong("8176887930741101556"), "op" : "c", "ns" : "admin.$cmd", "o" : { "applyOps" : [ { "ts" : { "t" : 1328805668000, "i" : 1 }, "h" : NumberLong("4788286707042615313"), "op" : "i", "ns" : "test.test", "o" : { "_id" : ObjectId("4f33f724b09cc797e9f6ce87") } } ] } }
{ "ts" : { "t" : 1328818575000, "i" : 1 }, "h" : NumberLong("7782250113577456557"), "op" : "c"
@ajdavis
ajdavis / gist:1808903
Created February 12, 2012 14:53
mongooplog output
$ mongo --port 4000
MongoDB shell version: 2.0.2
connecting to: 127.0.0.1:4000/test
PRIMARY> db.test.insert({'foo':'bar'})
PRIMARY> use local
PRIMARY> db.oplog.rs.find().sort({$natural:-1})
{ "ts" : { "t" : 1329058902000, "i" : 1 }, "h" : NumberLong("-9209932462579884476"), "op" : "i", "ns" : "test.test", "o" : { "_id" : ObjectId("4f37d45611558d5848a3d21a"), "foo" : "bar" } }
@ajdavis
ajdavis / reaper.py
Created February 29, 2012 03:20
Attempt to return socket to pool when thread dies
import thread
from thread import _local as local
import time
class Reaper(object):
def __init__(self, pool, sock):
self.pool = pool
self.sock = sock
def __del__(self):
print 'E.__del__'
@ajdavis
ajdavis / gist:2038545
Created March 14, 2012 18:40
referrers to socketinfo
<class 'pymongo.pool.SocketInfo'> SocketInfo(<socket._socketobject object at 0x2156930>, <pymongo.pool.Pool object at 0x2159670>) at 3 ...
| <type 'frame'> <frame object at 0xa24810>
| | <type 'frame'> <frame object at 0x467910>
| | | <type 'list'> [<frame object at 0xa24810>, {'sock_info': SocketInfo(<socket._socketobject object at 0x2156930>, <p ...
| | | | <type 'listiterator'> <listiterator object at 0x2159750>
| | | | | <type 'frame'> <frame object at 0xa24c10>
| | | | | | <type 'list'> [<listiterator object at 0x2159750>, [<frame object at 0x467910>, [<frame object at 0xa24810>, {'soc ...
| | | | | | <type 'frame'> <frame object at 0x467220>
| | | | | | <type 'list'> [<frame object at 0xa24c10>, [<listiterator object at 0x2159750>, [<frame object at 0x467910>, [<fra ...
| | | | | | <type 'frame'> <frame object at 0xa24e10>
@ajdavis
ajdavis / connection_test.py
Created March 27, 2012 03:23
Testing connection behavior in PyMongo
import os
import shutil
import threading
import sys
import time
import pymongo
import re
# Two steps: 1. run the test. 2. parse the log.
@ajdavis
ajdavis / async_test_engine.py
Created March 28, 2012 19:57
Generator-style Tornado asynchronous test tool
import os, time, functools, types, unittest
from tornado import gen, ioloop
import asyncmongo
import asyncmongo.errors
def async_test_engine(timeout_sec=5):
if not isinstance(timeout_sec, int) and not isinstance(timeout_sec, float):
raise TypeError(
"Expected int or float, got %s\n"
@ajdavis
ajdavis / tornado_test.py
Created March 28, 2012 20:33
Classic Tornado unittest for AsyncMongo
from tornado import ioloop, testing
import asyncmongo
import asyncmongo.errors
class MyTestCase(testing.AsyncTestCase):
def get_new_ioloop(self):
# See discussion at
# https://groups.google.com/d/msg/python-tornado/2xLfv0hhi54/CFIfX4WqLaAJ
return ioloop.IOLoop.instance()
@ajdavis
ajdavis / Benchmark.java
Created April 2, 2012 21:38
1M doc find() benchmark
import java.util.Calendar;
import java.util.TimeZone;
import java.util.List;
import java.util.Set;
import java.util.ArrayList;
import com.mongodb.Mongo;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
@ajdavis
ajdavis / gevent_play.py
Created April 10, 2012 13:15
Hanging Gevent test with PyMongo
import random
import threading
import os
import unittest
from gevent import Greenlet, monkey
from pymongo.connection import Connection
DB = "pymongo-pooling-tests"
@ajdavis
ajdavis / catenation.py
Created April 21, 2012 19:30
Comparing mem usage of str catenation and list joining
import os, random, string
nobjs = int(1e7)
objsz = 1
print 'str catenation'
print
s = ''
for i in range(nobjs):