-
Notifications
You must be signed in to change notification settings - Fork 183
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
Close the file after reading #139
Conversation
For further information see the following Most operating systems limit the number of file descriptors that may be open at any given time so it is critical to close the descriptor when operations are completed. Failure to do so will result in a memory leak that will eventually cause an application to crash. from https://nodejs.org/api/fs.html#fs_file_descriptors
Hmmm, the main problem still exist but this is not the correct solution... |
Hi @allwi290 thanks for raising this issue and preparing a PR. As you correctly state, this is an actual issue, but as you also have experienced, the solution does not work. The fetch function is called multiple times, so it is not possible to close after the first call. I think it is very inefficient to open/close the file at every read, so we need a solution at a higher level. |
When fetch is called you need to remember which file path to open
I'm parsing rain radar images and after roughly 65000 images I'v got |
Terrible slow if you open and close the file descriptor for each fetch... |
It was terrible slow due to my own misstake... One shot benchmark The performance for open and closing the file for each fetch is the same as for keeping it open all the time. I think this will depend on the type of harddrive of the system SSD vs HDD I have update my fork with this solution if you would like to try it out. |
@allwi290 I was thinking that you can actually solve this from the outside. Lets say this is how you access the file:
Internally, this is nothing else than:
The
The idea is to create an own factory function that returns an object with both
Now you can handle the TIFF like:
Please have a look at how |
Hi The only drawback, I can see with this solution, is that you need to handle the file source differently from the other sources (you need to remember to close it). Am I correct? Why do you want to create a new factory function instead of changing the existing one? |
That is true, sources of that type would need to be handled differently. On the other hand, a "close" on other sources would not make sense. I would also refrain from adding a I think I will integrate the above implementation in the built in factory function. On the other hand, if you have already implemented it, would you like to contribute your solution? We could simply reopen this PR for that purpose. |
@constantinius I can do it next week, if you can wait. |
@constantinius now you can review it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clean code, docs and tests, Very nice!
Thanks for fixing this issue
For further information see the following
Most operating systems limit the number of file descriptors that may be open at any given time so it is critical to close the descriptor when operations are completed. Failure to do so will result in a memory leak that will eventually cause an application to crash.
from https://nodejs.org/api/fs.html#fs_file_descriptors