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

Suggestion on how to reduce the transfered image size when using SQLite #2415

Closed
1 of 5 tasks
alpe12 opened this issue Jan 11, 2019 · 4 comments
Closed
1 of 5 tasks

Comments

@alpe12
Copy link
Contributor

alpe12 commented Jan 11, 2019

FEATURE REQUEST

  • I would like to propose an additional feature.

  • I would like to propose a config change.

  • I would like to request mod support.

  • I would like to propose another change.

  • I have searched the wiki and confirmed that this feature is not already implemented.

SQLite uses pages size of 4KB. That means that if a image stored has 5KB, it will actually use 8KB (2 pages of 4kb).
If the webpage has compression enabled, this is no problem, as compression takes care of that extra size. But if not (or using HTTPS) the full 8KB is sent unnecessarily.
What I have done (and recommend to be implemented) is to modify SQLite_tiles.php.

Replace this:
echo $row[0];

With this:
echo rtrim($row[0], "\0");

This trims the NUL characters at the end of image (they are not needed). Therefore, the exemple image now only transmit it's real size of 5KB instead of 8KB.
This is extremelly lightweight on CPU usage, hardly to make any changes even on very big servers, and saves KB on the transmitted image.
Since $row is already on memory, I don't think this will use more memory than it's already used.

(This may be useful on MySQL too).

@Psy-Virus
Copy link
Collaborator

I think even if it would use a bit more RAM, it is a good trade-off.
3KB / picture saved times 500,000 pictures (whats quite common) is about 1.5 GB traffic that's saved.

For me in particular: I have about 797,684 png files with an average size of 11.86KB. So it would save me 109MB if I had a traffic plan and if all files were loaded once and if I would use an SQL based save method.

For JPEG files the amount of saved traffic would probably be higher.

Why don't you create a Pull request?

@alpe12
Copy link
Contributor Author

alpe12 commented Jan 31, 2019

Good question.
Did it now.

@Psy-Virus
Copy link
Collaborator

:D great

@alpe12
Copy link
Contributor Author

alpe12 commented Feb 4, 2019

#2435

@alpe12 alpe12 closed this as completed Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants