You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made a simple http server example which works fine, except when uploading rather "larger" files.
Also get_arg is really slow (request.get_arg("file_name"));
See below for performance I get from Orbit profiler
Steps to Reproduce
Create simple httpserver
Upload "larger" file ( +20MB ) could be more/less
Expected behavior: Takes only a couple of seconds
Actual behavior: Very slow file upload
Reproduces how often: Always
Versions
Linux pop-os 5.15.15-76051515-generic #202201160435~1642693824~20.04~97db1bb-Ubuntu SMP Fri Jan 21 14: x86_64 x86_64 x86_64 GNU/Linux
Thanks for notifying. Taking a look at your code would help as well, so send it if you can.
There seem to be two different issues in here:
The file upload itself is slow: I think that some of the work happening in this PR (Add options to store files directly to the file system and to omit duplicating files in memory #257) should address that. The issue right now is that the library does quite a lot of work to load the file in memory both in the content and in the args. The PR introduces options to disable this behavior and make this faster.
The get_arg is slow: I believe this might be due to the argument getting being lazy and using the connection arguments when the data is preloaded already by the post_processor. A look at your code would help me understand if (1) can solve this as well or not.
The reason I implemented a new file upload handling was due to the slow upload speed in the previous libhttpserver. Especially I noticed, that the time to upload files did not increase linear (as I would have expected).
I also think that's due to the fact, that the data is stored to memory in chunks, which makes all the string handling (internal reallocating and concatenating) slower and slower the larger the file gets. Additionally it was always stored twice in memory. Once in the content and once in the args.
Additionally this could cause problems on embedded systems if the files are getting bigger but RAM is short.
So (in my opinion) the best solution is to let libhttpserver store the files to disk directly when it processes the data and not stuff it into the memory.
When I look at your provided code, you do lot's of the things on the retrieved arg, that the PR adds as features.
So you might want to look at the example for the file_upload in the PR.
Then you can get rid of the get_arg() completely, and the libhttpserver will already put the file to the file system within a specified directory and with a unique name.
Activity
[-][BUG] Title[/-][+][BUG] File upload very slow[/+]etr commentedon Mar 1, 2022
Thanks for notifying. Taking a look at your code would help as well, so send it if you can.
There seem to be two different issues in here:
The file upload itself is slow: I think that some of the work happening in this PR (Add options to store files directly to the file system and to omit duplicating files in memory #257) should address that. The issue right now is that the library does quite a lot of work to load the file in memory both in the content and in the args. The PR introduces options to disable this behavior and make this faster.
The
get_argis slow: I believe this might be due to the argument getting being lazy and using the connection arguments when the data is preloaded already by thepost_processor. A look at your code would help me understand if (1) can solve this as well or not.azertyalex commentedon Mar 2, 2022
I use
To spin up the webserver
And this
is my handler
ctomahogh commentedon Mar 3, 2022
A short comment on the mentioned PR #257
The reason I implemented a new file upload handling was due to the slow upload speed in the previous libhttpserver. Especially I noticed, that the time to upload files did not increase linear (as I would have expected).
I also think that's due to the fact, that the data is stored to memory in chunks, which makes all the string handling (internal reallocating and concatenating) slower and slower the larger the file gets. Additionally it was always stored twice in memory. Once in the content and once in the args.
Additionally this could cause problems on embedded systems if the files are getting bigger but RAM is short.
So (in my opinion) the best solution is to let libhttpserver store the files to disk directly when it processes the data and not stuff it into the memory.
When I look at your provided code, you do lot's of the things on the retrieved arg, that the PR adds as features.
So you might want to look at the example for the file_upload in the PR.
Then you can get rid of the get_arg() completely, and the libhttpserver will already put the file to the file system within a specified directory and with a unique name.
azertyalex commentedon Mar 3, 2022
okay, is there anything I can do at this moment to fix my issue or do I wait for #257 to come through?
etr commentedon Mar 3, 2022
The PR has just been approved, so you might want to try out if the new options are of any help to this case.
azertyalex commentedon Mar 4, 2022
I quickly put in the code and everything is blazing fast now 💯
Thanks guys!
etr commentedon Mar 4, 2022
Nice to hear; closing this issue then