]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/Slow_Filecheck_attachments___34__snails_it_all__34__/discussion.mdwn
Merge branch 'master' into cvs
[ikiwiki.git] / doc / bugs / Slow_Filecheck_attachments___34__snails_it_all__34__ / discussion.mdwn
1 ##Foreword :
2 Disabling of filecheck is not actually possible because btw it cause the attachment.pm to malfunction and
3 any of pagespec that could contain a *mimetype* condition.
4
5 attachment.pm imports "statically"  filecheck so actually disabling it should be *interdicted* .
6
7 <pre>
8 sub import {
9         add_underlay("attachment");
10         add_underlay("javascript");
11         add_underlay("jquery");
12         hook(type => "getsetup", id => "attachment", call => \&getsetup);
13         hook(type => "checkconfig", id => "attachment", call => \&checkconfig);
14         hook(type => "formbuilder_setup", id => "attachment", call => \&formbuilder_setup);
15         hook(type => "formbuilder", id => "attachment", call => \&formbuilder, last => 1);
16         IkiWiki::loadplugin("filecheck");
17 }
18 </pre>
19
20 ----
21
22 ## How bad is it ?
23
24 So I tried on three pages to inline <tt>!mimetype(image/*)</tt> while I allowed attachment of <tt>mimetype(image/*)</tt>
25
26 My profiling tests in the bug report shows that most of the time is spend in the "Fallback using file" block code,
27 I tried to comment that block and see how it'll perform. Obviously this is much much faster ... but is the mimetype
28 discovered using only *File::MimeInfo* ?
29
30
31 Dumping some strings before return to STDERR, rebuilding . This is just a  [[!toggle  id="code-test" text="dumpdebug adding"]] 
32
33 [[!toggleable  id="code-test" text="""
34 <pre>
35 sub match_mimetype ($$;@) {
36         my $page=shift;
37         my $wanted=shift;
38
39         my %params=@_;
40         my $file=exists $params{file} ? $params{file} : IkiWiki::srcfile($IkiWiki::pagesources{$page});
41         if (! defined $file) {
42                 return IkiWiki::ErrorReason->new("file does not exist");
43         }
44
45         # Get the mime type.
46         #
47         # First, try File::Mimeinfo. This is fast, but doesn't recognise
48         # all files.
49         eval q{use File::MimeInfo::Magic};
50         my $mimeinfo_ok=! $@;
51         my $mimetype;
52         print STDERR " --- match_mimetype (".$file.")\n";
53         if ($mimeinfo_ok) {
54                 my $mimetype=File::MimeInfo::Magic::magic($file);
55         }
56
57         # Fall back to using file, which has a more complete
58         # magic database.
59         #if (! defined $mimetype) {
60         #       open(my $file_h, "-|", "file", "-bi", $file);
61         #       $mimetype=<$file_h>;
62         #       chomp $mimetype;
63         #       close $file_h;
64         #}
65
66         if (! defined $mimetype || $mimetype !~s /;.*//) {
67                 # Fall back to default value.
68                 $mimetype=File::MimeInfo::Magic::default($file)
69                         if $mimeinfo_ok;
70                 if (! defined $mimetype) {
71                         $mimetype="unknown";
72                 }
73         }
74
75         my $regexp=IkiWiki::glob2re($wanted);
76         if ($mimetype!~$regexp) {
77                  print STDERR " xxx MIME unknown ($mimetype - $wanted - $regexp ) \n";
78                 return IkiWiki::FailReason->new("file MIME type is $mimetype, not $wanted");
79         }
80         else {
81                 print STDERR " vvv MIME found\n";
82                 return IkiWiki::SuccessReason->new("file MIME type is $mimetype");
83         }
84 }
85 </pre>
86 """]]
87
88 The results dump to stderr (or a file called... 'say *mime*) looks like this :
89 <pre>
90 --- match_mimetype (/usr/share/ikiwiki/attachment/ikiwiki/jquery.fileupload-ui.js)
91  xxx MIME unknown (text/plain - image/* - (?i-xsm:^image\/.*$) )
92  --- match_mimetype (/usr/share/ikiwiki/locale/fr/directives/ikiwiki/directive/fortune.mdwn)
93  xxx MIME unknown (text/plain - image/* - (?i-xsm:^image\/.*$) )
94  --- match_mimetype (/usr/share/ikiwiki/locale/fr/basewiki/shortcuts.mdwn)
95  xxx MIME unknown (text/plain - image/* - (?i-xsm:^image\/.*$) 
96  --- match_mimetype (/usr/share/ikiwiki/smiley/smileys/alert.png)
97  xxx MIME unknown (application/octet-stream - image/* - (?i-xsm:^image\/.*$) )
98  --- match_mimetype (/usr/share/ikiwiki/attachment/ikiwiki/images/ui-bg_flat_75_ffffff_40x100.png)
99  xxx MIME unknown (application/octet-stream - image/* - (?i-xsm:^image\/.*$) 
100 </pre>
101
102 <tt>---</tt> prepend signals the file on analysis<br/>
103 <tt>xxx</tt> prepend signals a returns failure : mime is unknown, the match is a failure<br/>
104 <tt>vvv</tt> prepend signals a return success.<br/>
105
106
107 This is nasty-scary results ! Something missed me or this mime-filecheck is plain nuts ?
108
109 *Question 1* : How many files have been analysed : **3055** (yet on a tiny tiny wiki)
110 <pre>grep "^ --- " mime | wc -l
111 3055
112 </pre>
113
114 *Question 2* : How many time it fails : *all the time*
115 <pre>
116  grep "^ xxx " mime | wc -l
117 3055
118 </pre>
119
120 *Question 1bis*  : Doh btw , how many files have been re-analysed ?  ** 2835 ** OMG !!
121 <pre>grep "^ --- " mime | sort -u | wc -l
122 220
123 </pre>
124
125 ## Conclusion
126
127 - Only the system command *file -bi* works. While it is **should** be easy on the cpu , it's also hard on the I/O -> VM :( 
128 - Something nasty with the mime  implementation and/or my system configuration -> Hints ? :D
129 - Need to cache during the rebuild : a same page needs not being rechecked for its mime while it's locked !
130
131
132 --mathdesc
133
134 > >        if ($mimeinfo_ok) {
135 > >                my $mimetype=File::MimeInfo::Magic::magic($file);
136 > >        }
137
138 > That seems strange to me, `my` restricts scope of $mimetype to enclosing if block, thus, assigned value will be dropped - I think, it is the problem.
139 > Try removing that stray `my`.
140 >
141 > --isbear