Skip to content
Snippets Groups Projects
Commit 002e245d authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

Task #8721: SW-280: processed review comment: removed user input and...

Task #8721: SW-280: processed review comment: removed user input and possibility to wipe production database. performance test now runs on a fresh database test instance
parent 975c77a8
No related branches found
No related tags found
No related merge requests found
...@@ -29,59 +29,79 @@ logger = logging.getLogger() ...@@ -29,59 +29,79 @@ logger = logging.getLogger()
def main(): def main():
from optparse import OptionParser from optparse import OptionParser
from lofar.common import dbcredentials from lofar.common import dbcredentials
import testing.postgresql
import psycopg2
# Check the invocation arguments # Check the invocation arguments
parser = OptionParser("%prog [options]", description='wipes the lta storageoverview database, and executes a performance test by inserting many files.') parser = OptionParser("%prog [options]", description='execute a performance test by inserting many files on an empty test database.')
parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging') parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging')
parser.add_option_group(dbcredentials.options_group(parser))
parser.set_defaults(dbcredentials="LTASO")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
level=logging.DEBUG if options.verbose else logging.INFO) level=logging.DEBUG if options.verbose else logging.INFO)
dbcreds = dbcredentials.parse_options(options)
logger.info("Using dbcreds: %s" % dbcreds.stringWithHiddenPassword()) # create a test webservice.db
logger.info(' creating test postgres server')
with testing.postgresql.Postgresql() as test_psql:
dsn = test_psql.dsn()
logger.info(' created test postgres server, dsn=%s', dsn)
base_date = datetime.utcnow() dbcreds = dbcredentials.Credentials()
dbcreds.user = 'test_user'
dbcreds.password = 'test_password'
db = store.LTAStorageDb(dbcreds, options.verbose) with psycopg2.connect(**dsn) as conn:
if raw_input('Are you sure you want to wipe the database? <y>/<n>:').lower() not in ['yes', 'y']: cursor = conn.cursor()
return #use same user/pass as stored in local webservice.dbcreds
query = "CREATE USER %s WITH SUPERUSER PASSWORD '%s'" % (dbcreds.user, dbcreds.password)
cursor.execute(query)
db.executeQuery('TRUNCATE lta.site CASCADE;', store.FETCH_NONE) create_script_path = os.path.normpath(os.path.join(os.environ['LOFARROOT'], 'share', 'ltaso', 'create_db_ltastorageoverview.sql'))
db.insertSite('sara', 'srm://srm.siteA.nl:8444') logger.info(' running ltaso create script create_script=%s', create_script_path)
rootdir_id = db.insertRootDirectory('sara', '/pnfs/grid.siteA.nl/data/lofar/ops') with open(create_script_path, 'r') as script:
projects_dir_id = db.insertSubDirectory(rootdir_id, '/pnfs/grid.siteA.nl/data/lofar/ops/projects') cursor.execute(script.read())
logger.info(' completed ltaso create script')
# junk_dir_id = db.insertSubDirectory(rootdir_id, '/pnfs/grid.siteA.nl/data/lofar/ops/misc') # copy the test postgres server settings into webservice.dbcreds
# fileinfos = [('testfile%d' % (i,), i+100, base_date, junk_dir_id) for i in range(0, 43)] # we can use these webservice.dbcreds in each test method to connect to the testing ltaso database
# file_ids = db.insertFileInfos(fileinfos) dbcreds.host = dsn['host']
# total_num_files_inserted = len(file_ids) dbcreds.database = dsn['database']
total_num_files_inserted = 0 dbcreds.port = dsn['port']
with open('db_perf.csv', 'w') as file: logger.info('finished setting up test LTASO database')
for cycle_nr in range(1, 10):
for project_nr in range(1, 10):
# project_name = 'lc%d_%03d/%d' % (cycle_nr, project_nr, os.getpid())
project_name = 'lc%d_%03d' % (cycle_nr, project_nr)
projectdir_id = db.insertSubDirectory(projects_dir_id, '/pnfs/grid.siteA.nl/data/lofar/ops/projects/%s' % (project_name,))
obs_base_id = cycle_nr*100000+project_nr*1000 base_date = datetime.utcnow()
for obs_nr, obsId in enumerate(range(obs_base_id, obs_base_id+20)):
obsName = 'L%s' % obsId
obsdir_id = db.insertSubDirectory(projectdir_id, '/pnfs/grid.siteA.nl/data/lofar/ops/projects/%s/%s' % (project_name, obsName)) db = store.LTAStorageDb(dbcreds, options.verbose)
fileinfos = [('%s_SB%3d' % (obsName, sbNr), 1000+sbNr+project_nr*cycle_nr, base_date + timedelta(days=10*cycle_nr+project_nr, minutes=obs_nr, seconds=sbNr), obsdir_id) for sbNr in range(0, 2)] db.insertSite('sara', 'srm://srm.siteA.nl:8444')
now = datetime.utcnow() rootdir_id = db.insertRootDirectory('sara', '/pnfs/grid.siteA.nl/data/lofar/ops')
file_ids = db.insertFileInfos(fileinfos) projects_dir_id = db.insertSubDirectory(rootdir_id, '/pnfs/grid.siteA.nl/data/lofar/ops/projects')
total_num_files_inserted += len(file_ids)
elapsed = totalSeconds(datetime.utcnow() - now) total_num_files_inserted = 0
line = '%s,%s' % (total_num_files_inserted, elapsed)
print line with open('db_perf.csv', 'w') as file:
file.write(line + '\n') for cycle_nr in range(1, 10):
for project_nr in range(1, 10):
# project_name = 'lc%d_%03d/%d' % (cycle_nr, project_nr, os.getpid())
project_name = 'lc%d_%03d' % (cycle_nr, project_nr)
projectdir_id = db.insertSubDirectory(projects_dir_id, '/pnfs/grid.siteA.nl/data/lofar/ops/projects/%s' % (project_name,))
obs_base_id = cycle_nr*100000+project_nr*1000
for obs_nr, obsId in enumerate(range(obs_base_id, obs_base_id+20)):
obsName = 'L%s' % obsId
obsdir_id = db.insertSubDirectory(projectdir_id, '/pnfs/grid.siteA.nl/data/lofar/ops/projects/%s/%s' % (project_name, obsName))
fileinfos = [('%s_SB%3d' % (obsName, sbNr), 1000+sbNr+project_nr*cycle_nr, base_date + timedelta(days=10*cycle_nr+project_nr, minutes=obs_nr, seconds=sbNr), obsdir_id) for sbNr in range(0, 2)]
now = datetime.utcnow()
file_ids = db.insertFileInfos(fileinfos)
total_num_files_inserted += len(file_ids)
elapsed = totalSeconds(datetime.utcnow() - now)
line = '%s,%s' % (total_num_files_inserted, elapsed)
print line
file.write(line + '\n')
if __name__ == "__main__": if __name__ == "__main__":
main() main()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment