Skip to content

Instantly share code, notes, and snippets.

@redbo
Last active August 29, 2015 14:05
Show Gist options
  • Save redbo/12a4ed9c6a020aee39fe to your computer and use it in GitHub Desktop.
Save redbo/12a4ed9c6a020aee39fe to your computer and use it in GitHub Desktop.
import time
import os
import uuid
import random
from swift.container.backend import ContainerBroker
from swift.common.utils import normalize_timestamp
INSERT_COUNT = 200
RECORD_COUNT = 300
try:
os.unlink('/tmp/something.db')
except Exception:
pass
x = ContainerBroker('/tmp/something.db', account='a', container='c')
x.initialize(normalize_timestamp(time.time()), 0)
start = time.time()
for _ in xrange(INSERT_COUNT):
records = [{'name': str(uuid.uuid4()),
'created_at': normalize_timestamp(time.time()), 'size': 0,
'content_type': 'text/plain',
'etag': 'd41d8cd98f00b204e9800998ecf8427e',
'deleted': 0,
'storage_policy_index': 0} for _ in xrange(RECORD_COUNT)]
# merge all new items
x.merge_items(records)
# merge where nothing changes
x.merge_items(records)
# merge where some things update
for record in records:
if random.randint(0, 1):
record['created_at'] = normalize_timestamp(time.time())
x.merge_items(records)
print time.time() - start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment