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

Improve query speed #1053

Open
focussing opened this issue Feb 15, 2025 · 3 comments
Open

Improve query speed #1053

focussing opened this issue Feb 15, 2025 · 3 comments
Assignees

Comments

@focussing
Copy link

Hello again @mevdschee,

Thank you again for developing this amazing API and dedicating your efforts to it.
Right now we have four machines (portable water purification) running.

For all kinds of logging every machine has a MySQL server and webserver running. Every 5 seconds a log is added.
Monitoring is done through a locally running website after logging on the machine.

At this moment we have around 1.000.000 records in the LOG table. When I want to retrieve the latest logging results I use a query as this:

/api.php/records/log?order=date,desc&page=1,720 (720 is for hone hour of log entries) and this takes around 3 seconds. What I don't understand is why this seems independent of the page size (1000 in this example). The response time for 72, 7200 or 72.000 as page size it is the roughly 3 seconds.
I added an index to the date column already (otherwise response time would be minutes).

Is there a way to speed up response times?

Looking forward to hearing from you.

@mevdschee
Copy link
Owner

mevdschee commented Feb 15, 2025

Hi Raymond

Thank you for your message.

Is there a way to speed up response times?

Yes, don't use pagination. Identify the last PK you have and ask for new records or use another field to match (with index) instead of pagination. Pagination requires sequential scanning.

/api.php/records/log?filter=date,ge,2025-02-15&filter=date,lt,2025-02-16

Use this to get all records of today and add hours if needed.

Kind regards,

Maurits

@mevdschee mevdschee self-assigned this Feb 15, 2025
@focussing
Copy link
Author

Hi Maurits,

Thank you for your speedy reply :)

This makes a HUGE difference. Now it takes for one hour of log entries around 180ms!

Two questions that I am curious of:

  1. Would it also make a difference if my index would be unique?
  2. Is there any way to compress the data which is returned? The json data for 2 columns for one week logging data is around 694 KB.

Kind regards,
Raymond

@mevdschee
Copy link
Owner

mevdschee commented Feb 16, 2025

Hi Raymond,

Great to hear that your results are good!

  1. Would it also make a difference if my index would be unique?

No

  1. Is there any way to compress the data which is returned?

Yes, the default solution is to use deflate/gzip on the webserver (nginx or apache) that executes the PHP script and the expected compression ratio is roughly 1:10 (sometimes even better). One could also achieve this from within PHP, but I see no (direct) reason why that would be preferred.

see: https://tecadmin.net/enable-gzip-compression-apache-ubuntu/
also: https://stackoverflow.com/questions/4709076/how-to-enable-gzip

Kind regards,

Maurits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants