Created
March 24, 2014 05:15
-
-
Save victorhooi/9734515 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| commit d2077d89d02c4a9eefdc85cb5dfa1557fba88086 | |
| Author: Thomas Rueckstiess <thomas@rueckstiess.net> | |
| Date: Mon Mar 24 16:11:05 2014 +1100 | |
| patch to run the script without creating data and on an existing mongod instance (single ok, on port 27017). | |
| diff --git a/index.py b/index.py | |
| index 2ac5a87..a4b4b82 100644 | |
| --- a/index.py | |
| +++ b/index.py | |
| @@ -17,20 +17,22 @@ class BuildIndexTest(object): | |
| self.parse_args(args) | |
| def bulk_insert(self, collection, n, off=0): | |
| - start = time.time() | |
| - for i in xrange(n / 100): | |
| - collection.insert([ | |
| - {"i": off + 100*i + j, "junk": "x" * 1024} | |
| - for j in xrange(100)]) | |
| - logging.info("Inserted %d objects in %0.1fs...", n, time.time() - start) | |
| + return | |
| + # start = time.time() | |
| + # for i in xrange(n / 1000): | |
| + # collection.insert([ | |
| + # {"i": off + 100*i + j, "junk": "x" * 1024} | |
| + # for j in xrange(1000)]) | |
| + # logging.info("Inserted %d objects in %0.1fs...", n, time.time() - start) | |
| def test_index_builds(self): | |
| - client = self.mongo.connect_primary() | |
| + # client = self.mongo.connect_primary() | |
| + client = pymongo.MongoClient() | |
| count = 0 | |
| logging.info("creating test.test_index") | |
| collection = client['test']['test_index'] | |
| while True: | |
| - insert = max(5 * count - count, 10000) | |
| + insert = 25000000 | |
| logging.info("Inserting %d items...", insert) | |
| self.bulk_insert(collection, insert, count) | |
| count += insert | |
| @@ -49,16 +51,17 @@ class BuildIndexTest(object): | |
| collection.drop_index("test_index") | |
| logging.info("Done. items=%d fg=%0.1f bg=%0.1f", count, fg, bg) | |
| + break | |
| def run(self): | |
| - with mongo.replset(mongod=self.options.mongod, | |
| - port=self.options.port, | |
| - verbose=self.options.verbose, | |
| - quickstart=False, | |
| - nodes=1) as self.mongo: | |
| - while True: | |
| - self.test_index_builds() | |
| + # with mongo.replset(mongod=self.options.mongod, | |
| + # port=self.options.port, | |
| + # verbose=self.options.verbose, | |
| + # quickstart=False, | |
| + # nodes=1) as self.mongo: | |
| + while True: | |
| + self.test_index_builds() | |
| if __name__ == '__main__': | |
| logging.basicConfig(level='INFO', format='[%(asctime)s %(process)s|%(levelname)s] %(message)s') | |
| diff --git a/mongo.py b/mongo.py | |
| index 8d42b26..0db6b8d 100644 | |
| --- a/mongo.py | |
| +++ b/mongo.py | |
| @@ -30,15 +30,23 @@ class ReplSet(object): | |
| if self.quickstart: | |
| extra_args.extend(['--smallfiles', '--noprealloc', '--nopreallocj']) | |
| - mongo = subprocess.Popen([ | |
| - self.mongod, | |
| - '--journal', | |
| - '--port', str(port), | |
| - '--replSet', self.rs_name, | |
| - '--dbpath', d, | |
| - '--logpath', os.path.join(d, 'mongo.log')] | |
| - + extra_args) | |
| - self.processes.append(mongo) | |
| + try: | |
| + mongo = subprocess.Popen([ | |
| + self.mongod, | |
| + '--journal', | |
| + '--port', str(port), | |
| + '--replSet', self.rs_name, | |
| + '--dbpath', d, | |
| + '--logpath', os.path.join(d, 'mongo.log')] | |
| + + extra_args) | |
| + self.processes.append(mongo) | |
| + | |
| + except OSError as e: | |
| + print e | |
| + print self.mongod | |
| + print os.path.join(d, 'mongo.log') | |
| + | |
| + | |
| def connect(self, port): | |
| while True: | |
| @@ -104,12 +112,12 @@ def add_mongod_options(parser): | |
| help='Base port to run mongod servers on', | |
| action='store', | |
| type='int', | |
| - default=9000) | |
| + default=27017) | |
| parser.add_option('--mongod', | |
| help='Path to mongod', | |
| action='store', | |
| type='string', | |
| - default='/usr/bin/mongod') | |
| + default='/usr/local/bin/mongod') | |
| parser.add_option('-v', | |
| dest='verbose', | |
| help='Make the mongod more verbose', |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment