Merge branch 'improve-perftest' into complex-geom-perf-improvements
This commit is contained in:
2609
release/observatory--1.1.5.sql
Normal file
2609
release/observatory--1.1.5.sql
Normal file
File diff suppressed because one or more lines are too long
@@ -1,5 +1,5 @@
|
||||
comment = 'CartoDB Observatory backend extension'
|
||||
default_version = '1.1.4'
|
||||
default_version = '1.1.5'
|
||||
requires = 'postgis, postgres_fdw'
|
||||
superuser = true
|
||||
schema = cdb_observatory
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
comment = 'CartoDB Observatory backend extension'
|
||||
default_version = '1.1.4'
|
||||
default_version = '1.1.5'
|
||||
requires = 'postgis, postgres_fdw'
|
||||
superuser = true
|
||||
schema = cdb_observatory
|
||||
|
||||
@@ -5,17 +5,47 @@ from util import query, commit
|
||||
|
||||
from time import time
|
||||
|
||||
import json
|
||||
import os
|
||||
|
||||
USE_SCHEMA = True
|
||||
|
||||
for q in (
|
||||
'DROP TABLE IF EXISTS obs_censustest',
|
||||
'''CREATE TABLE obs_censustest (cartodb_id SERIAL PRIMARY KEY,
|
||||
the_geom GEOMETRY, name TEXT, measure NUMERIC, category TEXT)''',
|
||||
'''INSERT INTO obs_censustest (the_geom, name)
|
||||
SELECT * FROM {schema}OBS_GetBoundariesByGeometry(
|
||||
st_makeenvelope(-74.05437469482422,40.66319159533881,
|
||||
-73.81885528564453,40.745696344339564, 4326),
|
||||
'us.census.tiger.block_group_clipped') As m(the_geom, geoid)'''
|
||||
'DROP TABLE IF EXISTS obs_perftest_simple',
|
||||
'''CREATE TABLE obs_perftest_simple (cartodb_id SERIAL PRIMARY KEY,
|
||||
point GEOMETRY,
|
||||
geom GEOMETRY,
|
||||
offset_geom GEOMETRY,
|
||||
name TEXT, measure NUMERIC, category TEXT)''',
|
||||
'''INSERT INTO obs_perftest_simple (point, geom, offset_geom, name)
|
||||
SELECT ST_PointOnSurface(the_geom) point,
|
||||
the_geom geom,
|
||||
ST_Translate(the_geom, -0.1, 0.1) offset_geom,
|
||||
geom_refs AS name
|
||||
FROM (SELECT * FROM {schema}OBS_GetBoundariesByGeometry(
|
||||
st_makeenvelope(-74.05437469482422,40.66319159533881,
|
||||
-73.81885528564453,40.745696344339564, 4326),
|
||||
'us.census.tiger.census_tract_clipped')) foo
|
||||
ORDER BY ST_NPoints(the_geom) ASC
|
||||
LIMIT 50''',
|
||||
'DROP TABLE IF EXISTS obs_perftest_complex',
|
||||
'''CREATE TABLE obs_perftest_complex (cartodb_id SERIAL PRIMARY KEY,
|
||||
point GEOMETRY,
|
||||
geom GEOMETRY,
|
||||
offset_geom GEOMETRY,
|
||||
name TEXT, measure NUMERIC, category TEXT)''',
|
||||
'''INSERT INTO obs_perftest_complex (point, geom, offset_geom, name)
|
||||
SELECT ST_PointOnSurface(the_geom) point,
|
||||
the_geom geom,
|
||||
ST_Translate(the_geom, -0.1, 0.1) offset_geom,
|
||||
geom_refs AS name
|
||||
FROM (SELECT * FROM {schema}OBS_GetBoundariesByGeometry(
|
||||
st_makeenvelope(-75.05437469482422,40.66319159533881,
|
||||
-73.81885528564453,41.745696344339564, 4326),
|
||||
'us.census.tiger.county_clipped')) foo
|
||||
ORDER BY ST_NPoints(the_geom) DESC
|
||||
LIMIT 50;''',
|
||||
'''SET statement_timeout = 5000;'''
|
||||
):
|
||||
query(q.format(
|
||||
schema='cdb_observatory.' if USE_SCHEMA else '',
|
||||
@@ -24,39 +54,89 @@ for q in (
|
||||
|
||||
|
||||
ARGS = {
|
||||
'OBS_GetMeasureByID': "name, 'us.census.acs.B01001002', '{}'",
|
||||
'OBS_GetMeasure': "{}, 'us.census.acs.B01001002'",
|
||||
'OBS_GetCategory': "{}, 'us.census.spielman_singleton_segments.X10'",
|
||||
('OBS_GetMeasureByID', None): "name, 'us.census.acs.B01001002', '{}'",
|
||||
('OBS_GetMeasure', 'predenominated'): "{}, 'us.census.acs.B01003001'",
|
||||
('OBS_GetMeasure', 'area'): "{}, 'us.census.acs.B01001002', 'area'",
|
||||
('OBS_GetMeasure', 'denominator'): "{}, 'us.census.acs.B01001002', 'denominator'",
|
||||
('OBS_GetCategory', None): "{}, 'us.census.spielman_singleton_segments.X10'",
|
||||
}
|
||||
|
||||
GEOMS = {
|
||||
'point': 'ST_PointOnSurface(the_geom)',
|
||||
'polygon_match': 'the_geom',
|
||||
'polygon_buffered': 'ST_Buffer(the_geom::GEOGRAPHY, 1000)::GEOMETRY(GEOMETRY, 4326)',
|
||||
}
|
||||
|
||||
def record(params, results):
|
||||
sha = os.environ['OBS_EXTENSION_SHA']
|
||||
fpath = os.path.join(os.environ['OBS_PERFTEST_DIR'], sha + '.json')
|
||||
if os.path.isfile(fpath):
|
||||
tests = json.load(open(fpath, 'r'))
|
||||
else:
|
||||
tests = {}
|
||||
with open(fpath, 'w') as fhandle:
|
||||
tests[json.dumps(params)] = {
|
||||
'params': params,
|
||||
'results': results
|
||||
}
|
||||
json.dump(tests, fhandle)
|
||||
|
||||
|
||||
@parameterized([
|
||||
('OBS_GetMeasureByID', 'us.census.tiger.block_group_clipped'),
|
||||
('OBS_GetMeasureByID', 'us.census.tiger.county'),
|
||||
('OBS_GetMeasure', GEOMS['point']),
|
||||
('OBS_GetMeasure', GEOMS['polygon_match']),
|
||||
('OBS_GetMeasure', GEOMS['polygon_buffered']),
|
||||
('OBS_GetCategory', GEOMS['point']),
|
||||
('OBS_GetCategory', GEOMS['polygon_match']),
|
||||
('OBS_GetCategory', GEOMS['polygon_buffered']),
|
||||
('simple', 'OBS_GetMeasureByID', None, 'us.census.tiger.census_tract'),
|
||||
('complex', 'OBS_GetMeasureByID', None, 'us.census.tiger.county'),
|
||||
|
||||
('simple', 'OBS_GetMeasure', 'predenominated', 'point'),
|
||||
('simple', 'OBS_GetMeasure', 'predenominated', 'geom'),
|
||||
('simple', 'OBS_GetMeasure', 'predenominated', 'offset_geom'),
|
||||
('simple', 'OBS_GetMeasure', 'area', 'point'),
|
||||
('simple', 'OBS_GetMeasure', 'area', 'geom'),
|
||||
('simple', 'OBS_GetMeasure', 'area', 'offset_geom'),
|
||||
('simple', 'OBS_GetMeasure', 'denominator', 'point'),
|
||||
('simple', 'OBS_GetMeasure', 'denominator', 'geom'),
|
||||
('simple', 'OBS_GetMeasure', 'denominator', 'offset_geom'),
|
||||
('simple', 'OBS_GetCategory', None, 'point'),
|
||||
('simple', 'OBS_GetCategory', None, 'geom'),
|
||||
('simple', 'OBS_GetCategory', None, 'offset_geom'),
|
||||
|
||||
#('complex', 'OBS_GetMeasure', 'predenominated', 'point'),
|
||||
#('complex', 'OBS_GetMeasure', 'predenominated', 'geom'),
|
||||
#('complex', 'OBS_GetMeasure', 'predenominated', 'offset_geom'),
|
||||
#('complex', 'OBS_GetMeasure', 'area', 'point'),
|
||||
#('complex', 'OBS_GetMeasure', 'area', 'geom'),
|
||||
#('complex', 'OBS_GetMeasure', 'area', 'offset_geom'),
|
||||
#('complex', 'OBS_GetMeasure', 'denominator', 'point'),
|
||||
#('complex', 'OBS_GetMeasure', 'denominator', 'geom'),
|
||||
#('complex', 'OBS_GetMeasure', 'denominator', 'offset_geom'),
|
||||
#('complex', 'OBS_GetCategory', None, 'point'),
|
||||
#('complex', 'OBS_GetCategory', None, 'geom'),
|
||||
#('complex', 'OBS_GetCategory', None, 'offset_geom'),
|
||||
])
|
||||
def test_performance(api_method, arg):
|
||||
print api_method, arg
|
||||
def test_performance(geom_complexity, api_method, normalization, geom):
|
||||
print api_method, geom_complexity, normalization, geom
|
||||
col = 'measure' if 'measure' in api_method.lower() else 'category'
|
||||
for rows in (1, 10, 50, 100):
|
||||
q = 'UPDATE obs_censustest SET {col} = {schema}{api_method}({args}) WHERE cartodb_id < {n}'.format(
|
||||
col=col,
|
||||
schema='cdb_observatory.' if USE_SCHEMA else '',
|
||||
api_method=api_method,
|
||||
args=ARGS[api_method].format(arg),
|
||||
n=rows+1)
|
||||
results = []
|
||||
|
||||
for rows in (1, 5, 10, ):
|
||||
stmt = '''UPDATE obs_perftest_{complexity}
|
||||
SET {col} = {schema}{api_method}({args})
|
||||
WHERE cartodb_id < {n}'''.format(
|
||||
col=col,
|
||||
complexity=geom_complexity,
|
||||
schema='cdb_observatory.' if USE_SCHEMA else '',
|
||||
api_method=api_method,
|
||||
args=ARGS[api_method, normalization].format(geom),
|
||||
n=rows+1)
|
||||
start = time()
|
||||
query(q)
|
||||
query(stmt)
|
||||
end = time()
|
||||
print rows, ': ', (rows / (end - start)), ' QPS'
|
||||
qps = (rows / (end - start))
|
||||
results.append({
|
||||
'rows': rows,
|
||||
'qps': qps,
|
||||
'stmt': stmt
|
||||
})
|
||||
print rows, ': ', qps, ' QPS'
|
||||
|
||||
if 'OBS_RECORD_TEST' in os.environ:
|
||||
record({
|
||||
'geom_complexity': geom_complexity,
|
||||
'api_method': api_method,
|
||||
'normalization': normalization,
|
||||
'geom': geom
|
||||
}, results)
|
||||
|
||||
Reference in New Issue
Block a user