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

Setting up watches takes Exponential time #36

Closed
Shne opened this issue May 9, 2012 · 3 comments
Closed

Setting up watches takes Exponential time #36

Shne opened this issue May 9, 2012 · 3 comments

Comments

@Shne
Copy link

Shne commented May 9, 2012

The initial set up of watches takes exponential time in the number of directories to such a degree it would take approximately 30 hours to set up watches on 100,000 directories on my laptop.

I can't test it right now, but I suspect the culprit is line 1855 in pyinotify.py (under python2) (1842 under python3):

if self.get_wd(rpath) is not None:
    # We decide to ignore paths already inserted into
    # the watch manager. Need to be removed with rm_watch()
    # first. Or simply call update_watch() to update it.
    continue

where it checks if a watch descriptor already exists for the directory.

It makes good sense to do when adding watches to dirs that could have been moved from elsewhere in a recursively watched dir, but in the initial set up of watches, if no moving/creating/deleting is being done, it just slows it down immensely. Should be doable in linear time.

So instead of removing this check altogether (if it is the culprit) I suggest a "static" flag or similar to disable the check on the initial watches setup when it is known that the hierarchy won't change during.

@Shne
Copy link
Author

Shne commented May 9, 2012

So i tested it now. With those two lines outcommented, setting up watches on about 101,000 folders now takes 2 seconds.

@Shne
Copy link
Author

Shne commented May 11, 2012

According to the man page for inotify_add_watch ( http://www.kernel.org/doc/man-pages/online/pages/man2/inotify_add_watch.2.html ), calling it on an already watched dir doesn't create a new watch descriptor, it just returns the already set wd. With those two lines commented out, the add_watch function's return array will also include wds for dirs that were already watched. I can't see where the problem lies in that.
Is there any problem in returning all wds, even the ones that were already set?

@seb-m
Copy link
Owner

seb-m commented Jun 6, 2012

You're right this is wrong, fixed in 439565e

Thanks for your help Jan.

@seb-m seb-m closed this as completed Jun 6, 2012
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