-
Notifications
You must be signed in to change notification settings - Fork 229
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
Adding a watch for a large directory on a slow drive is slow. #404
Comments
We have to subscribe to each folder individually, so it's listing 6000 files, looking for folders. So yes, it's linear on linux. And on linux you'll have to do that, otherwise you won't get events for nested folders. source Edit: earlier version stated we're listening on 6000 files, instead we have to look through all files |
Thanks for the reply. The source code explains why it's slow. I assume it's because it's calling metadata/is_dir on all files. Is this documented? I didn't know that setting a watch needs to stat all files in that dir. That's a lot of work (or it can be in some cases). And why do you need that? |
|
That's essentially the problem: We have to check for subdirectories and place watches on them. This is what requires going through the whole directory. |
Yes, I obviously did read what you quoted. It makes sense that you need to do this, if you want to watch a tree or sub-tree. But that not when watching a single directory. But, I'm not asking you to explain inotify to me. I'm going to trust that you know more about this than me.
What is the NoRecursive option for then? If I set NonRecursive I assume that you set one watch only. From the documentation:
Is there no way to subscribe to just the directory? I assumed that this is what NonRecursive means. But you closed this already, so that's that... |
Well then yes, then it's not going through the recursive lookup. I would recommend running strace and watching how long the actual linux call takes. My guess is that the linux kernel itself has to do a lot of book keeping for this. |
Okay, I did run my example code from above with strace. I also cloned the repo and put in some print statements. Please not again, that my example is using PollWatcher and NonRecursive.
Update:
Good that we talked about (and you linked to) inotify the whole time. |
So ok, sorry for missing that initially: If you want inotify, use the INotifyWatcher, or as I would recommend: The RecommendedWatcher |
What I don't get is, why did you choose something polling based when you wanted inotify and looked up the man page ? |
I missed that part of the documentation and just assumed it's also using inotify. Sorry. I'm going to use RecommendedWatcher. Thanks for your patience. I didn't want inotify. I wanted a cross platform solution. I only looked up the man page after you linked to inotify.rs. I used PollWatcher because it sends events only at a certain interval. But now I realize that the delay is a polling delay. It was my fault for not reading the documentation. Sorry again. |
Ah no worries, I just glanced over the code and assumed you're using the inotify watcher when specifically talking about inotify. The polling approach is only for 3rd party platforms or since #396 to watch syfs/procfs (listed specifically as unsupported by the manpage). |
Thanks again and I think we're done here. |
I know the title sounds stupid, but I couldn't figure out why it should be slow, or how to make it not slow.
Here's a basic example of what I'm doing:
System:
I was adding a watch for a directory with ca. 6000 images on a slow drive.
And it took more than a second just to set the watch.
Watching another directory with less files on the same drive was faster.
If I just use inotify-tools on the same dir it is immediate.
My question is:
The text was updated successfully, but these errors were encountered: