test currently running queries
(self)
| 322 | t.join() |
| 323 | |
| 324 | def test07_current_queries(self): |
| 325 | """test currently running queries""" |
| 326 | |
| 327 | # flush DB |
| 328 | self.conn.flushall() |
| 329 | |
| 330 | # shared variable, single consumer thread to exit |
| 331 | alive = True |
| 332 | |
| 333 | # issue a number of threads all running the same query |
| 334 | def issue_query(g, q): |
| 335 | while alive: |
| 336 | g.query(q) |
| 337 | |
| 338 | def issue_2_query(g, q1, q2): |
| 339 | while alive: |
| 340 | g.query(q1) |
| 341 | time.sleep(1) |
| 342 | g.query(q2) |
| 343 | |
| 344 | num_threads = multiprocessing.cpu_count() * 2 |
| 345 | |
| 346 | # create multiple connections |
| 347 | connections = [] |
| 348 | for i in range(num_threads+1): |
| 349 | connections.append(self.env.getConnection()) |
| 350 | |
| 351 | read_query = "MATCH (n) WHERE n.v > 100 RETURN count(1)" |
| 352 | write_query1 = "UNWIND range(1, 10000) AS x CREATE (v: x)" |
| 353 | write_query2 = "MATCH (n) DELETE n" |
| 354 | # create multiple threads |
| 355 | threads = [] |
| 356 | for i in range(num_threads): |
| 357 | # read queries |
| 358 | t = threading.Thread(target=issue_query, args=(Graph(connections[i], GRAPH_ID), read_query)) |
| 359 | threads.append(t) |
| 360 | |
| 361 | # write query |
| 362 | t = threading.Thread(target=issue_2_query, args=(Graph(connections[-1], GRAPH_ID), write_query1, write_query2)) |
| 363 | threads.append(t) |
| 364 | |
| 365 | # issue threads |
| 366 | for t in threads: |
| 367 | t.start() |
| 368 | |
| 369 | # wait for graph to be created |
| 370 | res = self.conn.type(GRAPH_ID) |
| 371 | while res != "graphdata": |
| 372 | res = self.conn.type(GRAPH_ID) |
| 373 | |
| 374 | # get waiting and running queries |
| 375 | |
| 376 | #----------------------------------------------------------------------- |
| 377 | # validate running queries |
| 378 | #----------------------------------------------------------------------- |
| 379 | |
| 380 | res = self.conn.execute_command("GRAPH.INFO") |
| 381 | while True: |