Пример #1
0
    def getPeople(self, options):
        conn = pymongo.Connection('localhost', 27017, tz_aware=False)
        dm = datamanager.MongoDataManager(
            conn,
            default_database='performance',
            root_database='performance',
            conflict_handler_factory=conflict.ResolvingSerialConflictHandler)
        if options.reload:
            conn.drop_database('performance')
            dm.root['people'] = people = People()

            # Profile inserts
            transaction.begin()
            t1 = time.time()
            for idx in xrange(options.size):
                klass = (self.personKlass if (MULTIPLE_CLASSES and idx % 2)
                         else self.person2Klass)
                people[None] = klass('Mr Number %.5i' % idx,
                                     random.randint(0, 100))
            transaction.commit()
            t2 = time.time()
            self.printResult('Insert', t1, t2, options.size)
        else:
            people = dm.root['people']

        return people
Пример #2
0
 def get(self):
     try:
         dm = LOCAL.data_manager
     except AttributeError:
         conn = self.pool.connection
         dm = LOCAL.data_manager = datamanager.MongoDataManager(
             conn, **self.dm_kwargs)
     return dm
Пример #3
0
def setUp(test):
    module.setUp(test)
    test.globs['conn'] = getConnection()
    test.globs['DBNAME'] = DBNAME
    cleanDB(test.globs['conn'], test.globs['DBNAME'])
    test.globs['commit'] = transaction.commit
    test.globs['dm'] = datamanager.MongoDataManager(
        test.globs['conn'],
        default_database=test.globs['DBNAME'],
        root_database=test.globs['DBNAME'])
Пример #4
0
def setUp(test):
    placelesssetup.setUp(test)
    module.setUp(test)
    test.globs['conn'] = testing.getConnection()
    test.globs['DBNAME'] = DBNAME
    testing.cleanDB(test.globs['conn'], test.globs['DBNAME'])
    test.globs['dm'] = datamanager.MongoDataManager(
        test.globs['conn'],
        default_database=test.globs['DBNAME'],
        root_database=test.globs['DBNAME'])

    # silence this, otherwise half-baked objects raise exceptions
    # on trying to __repr__ missing attributes
    test.orig_DEBUG_EXCEPTION_FORMATTER = \
        exceptionformatter.DEBUG_EXCEPTION_FORMATTER
    exceptionformatter.DEBUG_EXCEPTION_FORMATTER = 0
Пример #5
0
def run_basic_crud(options):
    conn = pymongo.Connection('localhost', 27017, tz_aware=False)
    dm = datamanager.MongoDataManager(
        conn,
        default_database='performance',
        root_database='performance',
        conflict_handler_factory=conflict.ResolvingSerialConflictHandler)
    if options.reload:
        conn.drop_database('performance')
        dm.root['people'] = people = People()

        # Profile inserts
        transaction.begin()
        t1 = time.time()
        for idx in xrange(options.size):
            klass = Person if (MULTIPLE_CLASSES and idx % 2) else Person2
            people[None] = klass('Mr Number %.5i' % idx,
                                 random.randint(0, 100))
        transaction.commit()
        t2 = time.time()
        printResult('Insert', t1, t2, options.size)
    else:
        people = dm.root['people']

    peopleCnt = len(people)
    # Profile slow read
    transaction.begin()
    t1 = time.time()
    [people[name].name for name in people]
    #cProfile.runctx(
    #    '[people[name].name for name in people]', globals(), locals())
    t2 = time.time()
    transaction.commit()
    printResult('Slow Read', t1, t2, peopleCnt)

    # Profile fast read (values)
    transaction.begin()
    t1 = time.time()
    [person.name for person in people.values()]
    #cProfile.runctx(
    #    '[person.name for person in people.find()]', globals(), locals())
    t2 = time.time()
    transaction.commit()
    printResult('Fast Read (values)', t1, t2, peopleCnt)

    # Profile fast read
    transaction.begin()
    t1 = time.time()
    [person.name for person in people.find()]
    #cProfile.runctx(
    #    '[person.name for person in people.find()]', globals(), locals())
    t2 = time.time()
    transaction.commit()
    printResult('Fast Read (find)', t1, t2, peopleCnt)

    # Profile object caching
    transaction.begin()
    t1 = time.time()
    [person.name for person in people.values()]
    [person.name for person in people.values()]
    #cProfile.runctx(
    #    '[person.name for person in people.values()]', globals(), locals())
    t2 = time.time()
    transaction.commit()
    printResult('Fast Read (caching x2)', t1, t2, peopleCnt * 2)

    transaction.begin()
    t1 = time.time()
    [person.name for person in people.values()]
    [person.name for person in people.values()]
    [person.name for person in people.values()]
    #cProfile.runctx(
    #    '[person.name for person in people.values()]', globals(), locals())
    t2 = time.time()
    transaction.commit()
    printResult('Fast Read (caching x3)', t1, t2, peopleCnt * 3)

    transaction.begin()
    t1 = time.time()
    [person.name for person in people.values()]
    [person.name for person in people.values()]
    [person.name for person in people.values()]
    [person.name for person in people.values()]
    #cProfile.runctx(
    #    '[person.name for person in people.values()]', globals(), locals())
    t2 = time.time()
    transaction.commit()
    printResult('Fast Read (caching x4)', t1, t2, peopleCnt * 4)

    if options.modify:
        # Profile modification
        t1 = time.time()

        def modify():
            for person in list(people.find()):
                person.name += 'X'
                person.age += 1
            transaction.commit()

        modify()
        #cProfile.runctx(
        #    'modify()', globals(), locals())
        t2 = time.time()
        printResult('Modification', t1, t2, peopleCnt)

    if options.delete:
        # Profile deletion
        t1 = time.time()
        for name in people.keys():
            del people[name]
        transaction.commit()
        t2 = time.time()
        printResult('Deletion', t1, t2, peopleCnt)