Last active
December 26, 2015 19:29
-
-
Save jeremydw/7201456 to your computer and use it in GitHub Desktop.
A simple test for Google's Cloud Datastore to see if property name length affects entity size on disk.
This file contains 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
application: jeremydw-hrd | |
version: property-name-length-test | |
api_version: 1 | |
runtime: python27 | |
threadsafe: true | |
handlers: | |
- url: /.* | |
script: main.application |
This file contains 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
import logging | |
import time | |
import webapp2 | |
from google.appengine.ext import ndb | |
from google.appengine.ext.db import stats | |
class PersistentClass1(ndb.Model): | |
super_very_long_property_name = ndb.StringProperty() | |
class PersistentClass2(ndb.Model): | |
l = ndb.StringProperty() | |
class TestHandler(webapp2.RequestHandler): | |
def get(self): | |
self.response.headers['Content-Type'] = 'text/plain' | |
# NOTE: You'll have to visit the development server admin console and press the "Generate stats" | |
# button from the "Datastore Stats" page in order for these statistics to be generated. | |
vals = stats.KindPropertyNameStat.all() | |
for val in vals: | |
self.response.out.write('name: {}, bytes: {}\n'.format(val.key().name(), val.bytes)) | |
bigger = stats.KindPropertyNameStat.get_by_key_name('super_very_long_property_name_PersistentClass1') | |
smaller = stats.KindPropertyNameStat.get_by_key_name('l_PersistentClass2') | |
self.response.out.write('difference: {} bytes'.format(bigger.bytes - smaller.bytes)) | |
class InitHandler(webapp2.RequestHandler): | |
"""Creates 2000 entities each for long and short property names.""" | |
def get(self): | |
self.response.headers['Content-Type'] = 'text/plain' | |
start = time.time() | |
entities = [] | |
for i in xrange(1, 2000): | |
key_id = 'persistent-class-1-{}'.format(i) | |
entity = PersistentClass1(id=key_id, super_very_long_property_name='foobar') | |
entities.append(entity) | |
ndb.put_multi(entities) | |
bigger_time = time.time() - start | |
self.response.out.write('Took {} seconds for long property names.\n'.format(bigger_time)) | |
start = time.time() | |
entities = [] | |
for i in xrange(1, 2000): | |
key_id = 'persistent-class-2-{}'.format(i) | |
entity = PersistentClass2(id=key_id, l='foobar') | |
entities.append(entity) | |
ndb.put_multi(entities) | |
shorter_time = time.time() - start | |
self.response.out.write('Took {} seconds for short property names.\n'.format(shorter_time)) | |
self.response.out.write('difference: {}'.format(bigger_time - shorter_time)) | |
application = webapp2.WSGIApplication([ | |
('/init', InitHandler), | |
('/test', TestHandler), | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results of running this using dev_appserver: