Beispiel #1
0
def main(args):
    global sent
    import pymongo
    from mongotools.pubsub import Channel
    cli = pymongo.MongoClient(w=0)
    chan = Channel(cli.test, 'mychannel')
    cli.test.mychannel.drop()
    chan.ensure_channel(capacity=int(args['--capacity']))
    names = ['t%.2d' % i for i in range(int(args['-c']))]
    threads = [
        threading.Thread(target=target,
                         args=(chan, name, int(args['-n']), int(args['-s'])))
        for name in names
    ]
    for t in threads:
        t.setDaemon(True)
        t.start()
    last = time.time()
    while True:
        time.sleep(10)
        now = time.time()
        elapsed = now - last
        print '%.1f mps' % (1.0 * sent / elapsed)
        sent = 0
        last = now
def main(args):
    global sent
    import pymongo
    from mongotools.pubsub import Channel
    cli = pymongo.MongoClient(w=0)
    chan = Channel(cli.test, 'mychannel')
    cli.test.mychannel.drop()
    chan.ensure_channel(capacity=int(args['--capacity']))
    names = [ 't%.2d' % i for i in range(int(args['-c'])) ]
    threads = [
        threading.Thread(
            target=target,
            args=(chan, name, int(args['-n']), int(args['-s'])))
        for name in names ]
    for t in threads:
        t.setDaemon(True)
        t.start()
    last = time.time()
    while True:
        time.sleep(10)
        now = time.time()
        elapsed = now-last
        print '%.1f mps' % (
            1.0 * sent / elapsed)
        sent=0
        last = now
def main(args):
    import pymongo
    from mongotools.pubsub import Channel
    cli = pymongo.MongoClient()
    chan = Channel(cli.test, 'mychannel')
    chan.ensure_channel()
    chan.sub(args['-t'], Benchmark(float(args['-s'])).handle)
    print 'Begin sub benchmark'

    while True:
        chan.handle_ready(raise_errors=True, await=True)
        time.sleep(0.1)
def main(args):
    import pymongo
    from mongotools.pubsub import Channel
    cli = pymongo.MongoClient()
    chan = Channel(cli.test, 'mychannel')
    chan.ensure_channel()
    chan.sub(args['-t'], Benchmark(float(args['-s'])).handle)
    print 'Begin sub benchmark'

    while True:
        chan.handle_ready(raise_errors=True, await=True)
        time.sleep(0.1)
Beispiel #5
0
 def new_channel(self):
     return Channel(self._session.db, self._name)
Beispiel #6
0
# Publisher
import pymongo
from mongotools.pubsub import Channel

cli = pymongo.MongoClient()

chan = Channel(cli.test, 'mychannel')
chan.ensure_channel()

chan.pub('foo')
chan.pub('bar', {'a':1})
chan.multipub([
    { 'k': 'bar', 'data': None },
    { 'k': 'baz', 'data':{'a':1}} ])
Beispiel #7
0
# Subscriber
import time
import pymongo
from mongotools.pubsub import Channel

cli = pymongo.MongoClient()

chan = Channel(cli.test, 'mychannel')
chan.ensure_channel()


def printer(chan, msg):
    print chan, msg


chan.sub('foo', printer)
chan.sub('bar', printer)

while True:
    chan.handle_ready(await=True)
    time.sleep(0.1)
# Subscriber
import time
import pymongo
from mongotools.pubsub import Channel

cli = pymongo.MongoClient()

chan = Channel(cli.test, 'mychannel')
chan.ensure_channel()

def printer(chan, msg):
    print chan, msg
    
chan.sub('foo', printer)
chan.sub('bar', printer)

while True:
    chan.handle_ready(await=True)
    time.sleep(0.1)