OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bench_system_tables Namespace Reference

Classes

class  HeavyAICon
 

Functions

def getOptions
 
def create_database
 
def create_insert_and_select_from_table
 
def create_dashboard
 
def create_user
 
def create_role
 
def assign_role
 
def grant_role_table_select
 
def grant_user_table_select
 
def drop_database
 
def drop_user
 
def drop_role
 
def query_and_time_system_table
 
def get_connection
 
def main
 

Function Documentation

def bench_system_tables.assign_role (   heavyai_con,
  user_id,
  role_id 
)

Definition at line 53 of file bench_system_tables.py.

Referenced by main().

53 
54 def assign_role(heavyai_con, user_id, role_id):
55  heavyai_con.query(f"GRANT test_role_{role_id} TO test_user_{user_id}")

+ Here is the caller graph for this function:

def bench_system_tables.create_dashboard (   heavyai_con,
  dashboard_id 
)

Definition at line 44 of file bench_system_tables.py.

Referenced by main().

44 
45 def create_dashboard(heavyai_con, dashboard_id):
46  heavyai_con.create_dashboard(f"test_dashboard_{dashboard_id}")

+ Here is the caller graph for this function:

def bench_system_tables.create_database (   heavyai_con,
  db_id 
)

Definition at line 35 of file bench_system_tables.py.

Referenced by main().

35 
36 def create_database(heavyai_con, db_id):
37  heavyai_con.query(f"CREATE DATABASE test_db_{db_id}")

+ Here is the caller graph for this function:

def bench_system_tables.create_insert_and_select_from_table (   heavyai_con,
  table_id 
)

Definition at line 38 of file bench_system_tables.py.

Referenced by main().

38 
39 def create_insert_and_select_from_table(heavyai_con, table_id):
40  heavyai_con.query(f"CREATE TABLE test_table_{table_id} (a INTEGER, b TEXT)")
41  for i in range(10):
42  heavyai_con.query(f"INSERT INTO test_table_{table_id} VALUES ({i}, 'abc_{i}')")
43  heavyai_con.query(f"SELECT AVG(a) FROM test_table_{table_id}")

+ Here is the caller graph for this function:

def bench_system_tables.create_role (   heavyai_con,
  role_id 
)

Definition at line 50 of file bench_system_tables.py.

Referenced by main().

50 
51 def create_role(heavyai_con, role_id):
52  heavyai_con.query(f"CREATE ROLE test_role_{role_id}")

+ Here is the caller graph for this function:

def bench_system_tables.create_user (   heavyai_con,
  user_id 
)

Definition at line 47 of file bench_system_tables.py.

Referenced by main().

47 
48 def create_user(heavyai_con, user_id):
49  heavyai_con.query(f"CREATE USER test_user_{user_id} (password = 'test_pass')")

+ Here is the caller graph for this function:

def bench_system_tables.drop_database (   heavyai_con,
  db_id 
)

Definition at line 62 of file bench_system_tables.py.

Referenced by main().

62 
63 def drop_database(heavyai_con, db_id):
64  heavyai_con.query(f"DROP DATABASE test_db_{db_id}")

+ Here is the caller graph for this function:

def bench_system_tables.drop_role (   heavyai_con,
  role_id 
)

Definition at line 68 of file bench_system_tables.py.

Referenced by main().

68 
69 def drop_role(heavyai_con, role_id):
70  heavyai_con.query(f"DROP ROLE test_role_{role_id}")

+ Here is the caller graph for this function:

def bench_system_tables.drop_user (   heavyai_con,
  user_id 
)

Definition at line 65 of file bench_system_tables.py.

Referenced by main().

65 
66 def drop_user(heavyai_con, user_id):
67  heavyai_con.query(f"DROP USER test_user_{user_id}")

+ Here is the caller graph for this function:

def bench_system_tables.get_connection (   options,
  db_name 
)

Definition at line 79 of file bench_system_tables.py.

Referenced by main().

79 
80 def get_connection(options, db_name):
81  return HeavyAICon(options.user, options.password, db_name, options.host)

+ Here is the caller graph for this function:

def bench_system_tables.getOptions (   args = None)

Definition at line 7 of file bench_system_tables.py.

Referenced by main().

7 
8 def getOptions(args=None):
9  parser = argparse.ArgumentParser(description='Basic benchmark for system tables')
10  parser.add_argument('--host', help='HEAVY.AI server address', default='localhost')
11  parser.add_argument('--port', help='HEAVY.AI server port', default='6273')
12  parser.add_argument('--user', help='HEAVY.AI user name', default='admin')
13  parser.add_argument('--password', help='HEAVY.AI password', default='HyperInteractive')
14  parser.add_argument('--database_count', help='Number of databases to create', default=1)
15  parser.add_argument('--table_count', help='Number of tables to create', default=100)
16  parser.add_argument('--dashboard_count', help='Number of dashboards to create', default=100)
17  parser.add_argument('--user_count', help='Number of users to create', default=10)
18  parser.add_argument('--role_count', help='Number of roles to create', default=5)
19  parser.add_argument('--skip_object_creation', help='Skip creation of database objects', default=False)
20  parser.add_argument('--skip_object_deletion', help='Skip deletion of database objects', default=False)
21  parser.add_argument('--tag', help='Tag for test run')
22  return parser.parse_args(args)

+ Here is the caller graph for this function:

def bench_system_tables.grant_role_table_select (   heavyai_con,
  role_id,
  db_id 
)

Definition at line 56 of file bench_system_tables.py.

Referenced by main().

56 
57 def grant_role_table_select(heavyai_con, role_id, db_id):
58  heavyai_con.query(f"GRANT SELECT ON DATABASE test_db_{db_id} TO test_role_{role_id}")

+ Here is the caller graph for this function:

def bench_system_tables.grant_user_table_select (   heavyai_con,
  user_id,
  db_id 
)

Definition at line 59 of file bench_system_tables.py.

Referenced by main().

59 
60 def grant_user_table_select(heavyai_con, user_id, db_id):
61  heavyai_con.query(f"GRANT SELECT ON DATABASE test_db_{db_id} TO test_user_{user_id}")

+ Here is the caller graph for this function:

def bench_system_tables.main (   argv)

Definition at line 82 of file bench_system_tables.py.

References assign_role(), create_dashboard(), create_database(), create_insert_and_select_from_table(), create_role(), create_user(), drop_database(), drop_role(), drop_user(), get_connection(), getOptions(), grant_role_table_select(), grant_user_table_select(), and query_and_time_system_table().

82 
83 def main(argv):
84  options = getOptions(argv)
85  default_db = "heavyai"
86  heavyai_con = get_connection(options, default_db)
87 
88  if not options.skip_object_creation:
89  print("Creating database objects")
90  for db_id in range(options.database_count):
91  create_database(heavyai_con, db_id)
92  db_name = f"test_db_{db_id}"
93  heavyai_con = get_connection(options, db_name)
94  for table_id in range(options.table_count):
95  create_insert_and_select_from_table(heavyai_con, table_id)
96  print(f"{options.table_count} tables created for {db_name}")
97  for dashboard_id in range(options.dashboard_count):
98  create_dashboard(heavyai_con, dashboard_id)
99  print(f"{options.dashboard_count} dashboards created for {db_name}")
100  print(f"{options.database_count} databases created")
101 
102  heavyai_con = get_connection(options, default_db)
103  for user_id in range(options.user_count):
104  create_user(heavyai_con, user_id)
105  print(f"{options.user_count} users created")
106 
107  for role_id in range(options.role_count):
108  create_role(heavyai_con, role_id)
109  print(f"{options.role_count} roles created")
110 
111  half_roles = int(options.role_count / 2)
112  for user_id in range(options.user_count):
113  for role_id in range(half_roles):
114  assign_role(heavyai_con, user_id, role_id)
115 
116  if options.database_count > 0:
117  db_id = 0
118  for role_id in range(half_roles):
119  grant_role_table_select(heavyai_con, role_id + half_roles, db_id)
120 
121  half_users = int(options.user_count / 2)
122  for user_id in range(half_users):
123  grant_user_table_select(heavyai_con, user_id + half_users, db_id)
124 
125  system_tables = ["tables",
126  "dashboards",
127  "databases",
128  "users",
129  "permissions",
130  "role_assignments",
131  "roles",
132  "storage_details",
133  "memory_details",
134  "memory_summary"]
135  heavyai_con = get_connection(options, "information_schema")
136  print("Executing system table queries")
137  for table_name in system_tables:
138  query_and_time_system_table(heavyai_con, table_name)
139 
140  if not options.skip_object_deletion:
141  heavyai_con = get_connection(options, default_db)
142  print("Dropping databases")
143  for db_id in range(options.database_count):
144  drop_database(heavyai_con, db_id)
145 
146  print("Dropping users")
147  for user_id in range(options.user_count):
148  drop_user(heavyai_con, user_id)
149 
150  print("Dropping roles")
151  for role_id in range(options.role_count):
152  drop_role(heavyai_con, role_id)

+ Here is the call graph for this function:

def bench_system_tables.query_and_time_system_table (   heavyai_con,
  table_name 
)

Definition at line 71 of file bench_system_tables.py.

Referenced by main().

71 
72 def query_and_time_system_table(heavyai_con, table_name):
73  query = f"SELECT COUNT(*) FROM {table_name}"
74  result = heavyai_con.query(query)
75  print(f"Query: {query}, Execution time: {result._result.execution_time_ms}ms")
76  query = f"SELECT * FROM {table_name} LIMIT 10"
77  result = heavyai_con.query(query)
78  print(f"Query: {query}, Execution time: {result._result.execution_time_ms}ms")

+ Here is the caller graph for this function: