Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

["BUG"] Inneficient queries using the Tag model #119

Open
jfavellar90 opened this issue Dec 5, 2024 · 3 comments
Open

["BUG"] Inneficient queries using the Tag model #119

jfavellar90 opened this issue Dec 5, 2024 · 3 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@jfavellar90
Copy link
Member

jfavellar90 commented Dec 5, 2024

Describe the bug
This is happening in eox-tagging 5.0.0. In the last two weeks, we noticed a service degradation in one of our installations due to expensive queries. Such queries are related to fetching the Tag model objects. We discovered that those queries stress the MySQL server too much, resulting in very slow response times. Below, you'll find a graph displaying the response time for the TAG select queries during a period of service degradation:

Screenshot from 2024-12-05 15-13-55

With a low throughput (10-15 queries per minute), the response is pretty slow. Additionally, given that the database is stressed, other endpoints responses are also affected.
What is triggering these queries?? The most important source we've identified is the rendering of the certificates using the Tag model on their templates. Those templates include Python lines (thanks to Mako) like:

from eox_tagging.models import Tag

def get_tags(username, course_id):
  tags = {}
  certificate_tags = Tag.objects.find_all_tags_for("generatedcertificate", {"username": username, "course_id": course_id})

  for tag in certificate_tags:
    tags[tag.tag_type]= tag.tag_value

  return tags

tags = get_tags(username, course_id)

By running a simple query, we can find the certificate templates invoking the tagging model:

select id, name, is_active from certificates_certificatetemplate where template like "%eox_tagging.models%";

To Reproduce
Steps to reproduce the behavior:

  1. Find a certificate ID rendered from a template using the TAG model (we can help with that)
  2. Access the URL https://< lms-site >/certificates/< certificate-id >
  3. This will trigger the slow query. The LMS takes about 7-8 seconds to respond
  4. There's no error displayed, however, when having concurrent requests pointing to the same problematic certificate generation, a service degradation occurs.

Expected behavior
Querying the Tag model shouldn't generate service degradation. Rendering certificates querying the Tag model shouldn't take too long (a normal response should be between 2-3 seconds according to other certificate rendering tests)

Screenshots
XXX

Additional context
This is probably related to indexes lacking. Right now the table contains about 5,4 million records. An example of a slow query is displayed below:

SELECT `eox_tagging_tag`.`id`, `eox_tagging_tag`.`key`, `eox_tagging_tag`.`tag_value`, `eox_tagging_tag`.`tag_type`, `eox_tagging_tag`.`access`, `eox_tagging_tag`.`activation_date`, `eox_tagging_tag`.`expiration_date`, `eox_tagging_tag`.`created_at`, `eox_tagging_tag`.`status`, `eox_tagging_tag`.`inactivated_at`, `eox_tagging_tag`.`target_type_id`, `eox_tagging_tag`.`target_object_id`, `eox_tagging_tag`.`owner_type_id`, `eox_tagging_tag`.`owner_object_id` FROM `eox_tagging_tag` WHERE (`eox_tagging_tag`.`target_object_id` IN (<any_object_id>) AND `eox_tagging_tag`.`target_type_id` = <any_target_type_id>)
@jfavellar90 jfavellar90 added bug Something isn't working help wanted Extra attention is needed labels Dec 5, 2024
@magajh
Copy link
Contributor

magajh commented Dec 6, 2024

@jfavellar90 Thank you for the report. In the steps to reproduce the behavior, is the URL to trigger the query correct? https:///certificates/

@jfavellar90
Copy link
Member Author

@magajh I fixed the URL. If you need a specific example, please let me know

@DeimerM
Copy link

DeimerM commented Dec 6, 2024

Template del certificado generando el issue:

template-inefop.txt

@magajh magajh self-assigned this Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants