I don't understand the extraction/saving at KB/s? You mean CPU time or?
Extracting and saving "large" binary file
Hi guys!
Here is the thing, I have some binary files (logs) wich I upload to my webapp. The webapp run Laravel, it extracts all informations from the binary file and store it to a MySQL database.
Problem is, the binary files can be up to 5 or 8MB. I can extract data at 300kB/s and save those at 30kB/s to the DB. Which means that it takes up to 294s, almost 5 minutes! And I don't even count the time to upload an 8MB file to the server...
Question is, is there a way to not get an active connection for more than 5 minutes to extract datas and store them to the DB? Like running a PHP command in background? My first thought was using a cron for that but it looks crappy from the outside...
Any thoughts?
Ok guys!
I just did some little optimization and I manage to go from 19s to less than 5s with a 600kB file (extraction + saving)!!
What I've done:
- Don't know why but for the extraction I read the file each time I needed it.. So I've made a method getContent that checks if the $content attribute is set or not. If not it puts the whole file in it then return $content. Divide by almost 2 the execution time of extraction!
- Thanks to @phildawson and this awesome link: https://dev.mysql.com/doc/refman/5.7/en/optimizing-innodb-bulk-data-loading.html with just the first points, the saving time (for a 600kB file) went from 15s down to 1.33s!!
- Other thing I did, and this one is pretty simple... Just disable the db collector of the Laravel Debugbar and gain like 1 or 2s.
The results are pretty good for what I do so I think I'll stick with that for now and use Queues after.
Thanks to everyone!
Please or to participate in this conversation.