superset icon indicating copy to clipboard operation
superset copied to clipboard

Slices backed by AWS Athena load sequentially, not in parallel.

Open sjmeyer opened this issue 8 years ago • 15 comments

Make sure these boxes are checked before submitting your issue - thank you!

  • [x] I have checked the superset logs for python stacktraces and included it here as text if any
  • [x] I have reproduced the issue with at least the latest released version of superset
  • [x] I have checked the issue tracker for the same issue and I haven't found one similar

Superset version

Versions: 0.22.1, 0.23, 0.25.6

Expected results

Slices should load simultaneously. Athena logs should also show queries to be called at the same time.

Actual results

Slices load one after the other, making for poor user experience. The Athena logs also shows a query is called only once the previous one finishes.

Athena log timestamps:

2018/06/25 13:53:43 UTC+-2 Query...
2018/06/25 13:53:41 UTC+-2 Query...
2018/06/25 13:53:37 UTC+-2 Query...
2018/06/25 13:53:36 UTC+-2 Query...
2018/06/25 13:53:36 UTC+-2 Query...
2018/06/25 13:53:34 UTC+-2 Query...
2018/06/25 13:53:31 UTC+-2 Query...

Steps to reproduce

  • Build a dashboard with multiple slices, each built on it's own Athena query.

  • Use the below gunicorn command line arguments:

    GUNICORN_CMD_ARGS "-w 2 -k gevent --threads 12 --timeout 120 -b 0.0.0.0:8088 --limit-request-line 0 --limit-request-field_size 0 --proxy-protocol true --proxy-allow-from * --forwarded-allow-ips * --keep-alive 75"

sjmeyer avatar Jun 25 '18 12:06 sjmeyer

We typically run with single thread and many workers as it's unclear what it would take to get sqlalchemy to work nicely with thread. Have you tried that option, say -w 16 and no --threads {}?

mistercrunch avatar Jun 25 '18 18:06 mistercrunch

I changed my configuration to what you suggested. I tried both with 8 workers and 16 workers and no --threads argument. Neither of these worked.

I can still see queries running one after the other in the Athena logs.

sjmeyer avatar Jun 27 '18 09:06 sjmeyer

Looks like Athena is the thing limiting concurrency somehow.

mistercrunch avatar Jun 27 '18 15:06 mistercrunch

I don't think the issue is Athena limiting concurrent queries. According to the documentation by default you can run 20 SELECT queries concurrently.

Is it possible that this issue is with SQLAlchemy? I saw some packages that you can use to run queries in parallel with SQLAlchemy and gevent, but it need some custom code and I only saw the package available for Python 2. Not sure if the current implementation already runs queries for dashboard loading in parallel?

sjmeyer avatar Jun 28 '18 08:06 sjmeyer

@mistercrunch I'm busy doing some more digging around and found something interesting. I am logging out the timestamp when the Ajax from a slice hits the explore_json endpoint, and I'm logging out when the query() method is called to execute the query. Even though I have 16 workers, only 4 Ajax calls are handled at first. After that some are staggered and some are handled two by two.

When it comes to executing the queries, they are being run in sequence. It is clear from the logs that one is waiting for another to finish before running. Is it possible that the issue is with the JDBC driver or the way in which that connection is made?

Also, any idea why only 4 Ajax requests would be handled even when 16 workers are used?

sjmeyer avatar Jul 05 '18 08:07 sjmeyer

What's your -w argument?

mistercrunch avatar Jul 05 '18 14:07 mistercrunch

@mistercrunch My -w argument is 16. The full ENV "GUNICORN_CMD_ARGS" is:

-w 16 -k gevent --timeout 120 -b  0.0.0.0:8088 --limit-request-line 0  --limit-request-field_size 0 --proxy-protocol true --proxy-allow-from * --forwarded-allow-ips * --keep-alive 75"

The application is running in a container on a linux server. The container's max memory is 8GB and it has no limit on the CPU (quad core). It is not an issue with either memory or CPU, it is well within the limits, based on docker stats.

I've been trying to figure out exactly where the call to Athena actually happens, to see if it's some kind of issue with that. I see that the "create_engine" method is called for each query. Should the connection not persist? Each query has a boto3 call to authenticate the query. Is that correct?

Under database settings I see that you can enable/disable asynchronous queries. But asynchronous queries expect Celery workers to be setup. Would you advise using this setting and the celery workers for use in a system that should scale out/in based on demand? Or is this purely for long running queries?

sjmeyer avatar Jul 05 '18 22:07 sjmeyer

The Celery workers are mostly there to deal with long running queries and heavy workloads.

create_engine being called for each query is right, we do not use connection pooling for external databases, only for the connections to the metadata database.

mistercrunch avatar Jul 06 '18 14:07 mistercrunch

@mistercrunch It seems like the issue is the running of the JDBC driver jar. A new JVM gets created for each connection, instead of threads being added to one running JVM. I think it has something to do with SQLAlchemy wanting one thread per process.

sjmeyer avatar Jul 09 '18 14:07 sjmeyer

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. For admin, please label this issue .pinned to prevent stale bot from closing the issue.

stale[bot] avatar Apr 10 '19 19:04 stale[bot]

Hi @sjmeyer Is there a way to config PyAthena to send multiple queries to Athena so that Superset can have better performance on dashboard which have more than 10 slices. Everytime I apply a filters, it takes 45s to fully load visualization for all slices

LeoDiep avatar Aug 05 '23 12:08 LeoDiep

Hi @sjmeyer @LeoDiep: Is this issue resolved? same issue I am experiencing even after enabling Global Async queries. Opened a new ticket as this ticket is marked as completed https://github.com/apache/superset/issues/25827

Abhijith-Nagaraja avatar Nov 02 '23 02:11 Abhijith-Nagaraja

Hi @sjmeyer @LeoDiep: Is this issue resolved? same issue I am experiencing even after enabling Global Async queries. Opened a new ticket as this ticket is marked as completed #25827

Hi, I solved my problem by increasing the number of gunicorn workers from 1 (default) to 6 workers, now 45s decrease to 6s

LeoDiep avatar Nov 03 '23 03:11 LeoDiep

@LeoDiep : That's what I ended up doing. Thanks for suggesting it. Although I don't know why async queries are not working. I hope someone from superset team reviews by request in https://github.com/apache/superset/issues/25827

Abhijith-Nagaraja avatar Nov 03 '23 20:11 Abhijith-Nagaraja

@LeoDiep : That's what I ended up doing. Thanks for suggesting it. Although I don't know why async queries are not working. I hope someone from superset team reviews by request in #25827

I guess async queries are only applied to long response time queries (more than 10s each) so that the sql lab doesn't get stuck when querying other queries

LeoDiep avatar Nov 05 '23 14:11 LeoDiep