| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>ProFTPD module mod_statcache</title> |
| 5 | </head> |
| 6 | |
| 7 | <body bgcolor=white> |
| 8 | |
| 9 | <hr> |
| 10 | <center> |
| 11 | <h2><b>ProFTPD module <code>mod_statcache</code></b></h2> |
| 12 | </center> |
| 13 | <hr><br> |
| 14 | |
| 15 | <p> |
| 16 | The <code>mod_statcache</code> module is designed to cache the results |
| 17 | of <code>stat(2)</code> and <code>lstat(2)</code> calls in shared memory, |
| 18 | so that the results can be shared among multiple session processes. On |
| 19 | a busy server, especially one handling many directory listings, these |
| 20 | <code>stat(2)</code>/<code>lstat(2)</code> calls can add quite a bit of |
| 21 | overhead. |
| 22 | |
| 23 | <p> |
| 24 | This module is contained in the <code>mod_statcache.c</code> file for |
| 25 | ProFTPD 1.3.<i>x</i>, and is not compiled by default. Installation |
| 26 | instructions are discussed <a href="#Installation">here</a>. More examples |
| 27 | of <code>mod_statcache</code> usage can be found <a href="#Usage">here</a>. |
| 28 | |
| 29 | <p> |
| 30 | The most current version of <code>mod_statcache</code> is distributed with the |
| 31 | ProFTPD source code. |
| 32 | |
| 33 | <h2>Author</h2> |
| 34 | <p> |
| 35 | Please contact TJ Saunders <tj <i>at</i> castaglia.org> with any |
| 36 | questions, concerns, or suggestions regarding this module. |
| 37 | |
| 38 | <h2>Directives</h2> |
| 39 | <ul> |
| 40 | <li><a href="#StatCacheCapacity">StatCacheCapacity</a> |
| 41 | <li><a href="#StatCacheControlsACLs">StatCacheControlsACLs</a> |
| 42 | <li><a href="#StatCacheEngine">StatCacheEngine</a> |
| 43 | <li><a href="#StatCacheMaxAge">StatCacheMaxAge</a> |
| 44 | <li><a href="#StatCacheTable">StatCacheTable</a> |
| 45 | </ul> |
| 46 | |
| 47 | <h2>Control Actions</h2> |
| 48 | <ul> |
| 49 | <li><a href="#statcache"><code>statcache</code></a> |
| 50 | </ul> |
| 51 | |
| 52 | <p> |
| 53 | <hr> |
| 54 | <h3><a name="StatCacheCapacity">StatCacheCapacity</a></h3> |
| 55 | <strong>Syntax:</strong> StatCacheCapacity <em>count</em><br> |
| 56 | <strong>Default:</strong> <em>StatCacheCapacity 5000</em><br> |
| 57 | <strong>Context:</strong> server config<br> |
| 58 | <strong>Module:</strong> mod_statcache<br> |
| 59 | <strong>Compatibility:</strong> 1.3.4rc2 and later |
| 60 | |
| 61 | <p> |
| 62 | The <code>StatCacheCapacity</code> directive configures the <i>capacity</i> |
| 63 | of the cache, <i>i.e.</i> the maximum number of cache entries. By default, |
| 64 | <code>mod_statcache</code> allocates space for 5000 cache entries. |
| 65 | |
| 66 | <p> |
| 67 | The <em>count</em> value be 10 or greater. The configured <em>count</em> |
| 68 | is handled as a <i>hint</i>; the actual allocated capacity may be rounded up |
| 69 | to the nearest multiple of the internal block sizes. |
| 70 | |
| 71 | <p> |
| 72 | <hr> |
| 73 | <h3><a name="StatCacheControlsACLs">StatCacheControlsACLs</a></h3> |
| 74 | <strong>Syntax:</strong> StatCacheControlsACLs <em>actions|"all" "allow"|"deny" "user"|"group" list</em><br> |
| 75 | <strong>Default:</strong> None<br> |
| 76 | <strong>Context:</strong> server config<br> |
| 77 | <strong>Module:</strong> mod_statcache<br> |
| 78 | <strong>Compatibility:</strong> 1.3.4rc2 and later |
| 79 | |
| 80 | <p> |
| 81 | The <code>StatCacheControlsACLs</code> directive configures access lists of |
| 82 | <em>users</em> or <em>groups</em> who are allowed (or denied) the ability to |
| 83 | use the <em>actions</em> implemented by <code>mod_statcache</code>. The default |
| 84 | behavior is to deny everyone unless an ACL allowing access has been explicitly |
| 85 | configured. |
| 86 | |
| 87 | <p> |
| 88 | If "allow" is used, then <em>list</em>, a comma-delimited list |
| 89 | of <em>users</em> or <em>groups</em>, can use the given <em>actions</em>; all |
| 90 | others are denied. If "deny" is used, then the <em>list</em> of |
| 91 | <em>users</em> or <em>groups</em> cannot use <em>actions</em> all others are |
| 92 | allowed. Multiple <code>StatCacheControlsACLs</code> directives may be used to |
| 93 | configure ACLs for different control actions, and for both users and groups. |
| 94 | |
| 95 | <p> |
| 96 | The <em>action</em> provided by <code>mod_statcache</code> is |
| 97 | <a href="#statcache">"statcache"</a>. |
| 98 | |
| 99 | <p> |
| 100 | Examples: |
| 101 | <pre> |
| 102 | # Allow only user root to examine cache stats |
| 103 | StatCacheControlsACLs all allow user root |
| 104 | </pre> |
| 105 | |
| 106 | <p> |
| 107 | <hr> |
| 108 | <h3><a name="StatCacheEngine">StatCacheEngine</a></h3> |
| 109 | <strong>Syntax:</strong> StatCacheEngine <em>on|off</em><br> |
| 110 | <strong>Default:</strong> <em>StatCacheEngine off</em><br> |
| 111 | <strong>Context:</strong> server config, <code><VirtualHost></code>, <code><Global></code><br> |
| 112 | <strong>Module:</strong> mod_statcache<br> |
| 113 | <strong>Compatibility:</strong> 1.3.4rc2 and later |
| 114 | |
| 115 | <p> |
| 116 | The <code>StatCacheEngine</code> directive enables or disables the module's |
| 117 | caching of <code>stat(2)</code> and <code>lstat(2)</code> calls. |
| 118 | |
| 119 | <p> |
| 120 | <hr> |
| 121 | <h3><a name="StatCacheMaxAge">StatCacheMaxAge</a></h3> |
| 122 | <strong>Syntax:</strong> StatCacheMaxAge <em>positive-cache-age [negative-cache-age]</em><br> |
| 123 | <strong>Default:</strong> <em>StatCacheMaxAge 5</em><br> |
| 124 | <strong>Context:</strong> server config<br> |
| 125 | <strong>Module:</strong> mod_statcache<br> |
| 126 | <strong>Compatibility:</strong> 1.3.4rc2 and later |
| 127 | |
| 128 | <p> |
| 129 | The <code>StatCacheMaxAge</code> directive configures how long the |
| 130 | <code>mod_statcache</code> module will keep the <code>stat(2)</code> or |
| 131 | <code>lstat(2)</code> results cached for a given path. By default, |
| 132 | <code>mod_statcache</code> will cache results for 5 seconds (and will |
| 133 | cache <i>failed</i> <code>stat(2)</code>/<code>lstat(2)</code> calls for |
| 134 | 1 second). |
| 135 | |
| 136 | <p> |
| 137 | If you configure a single age parameter, then that value will be used for |
| 138 | both positive and negative cache entries. Thus: |
| 139 | <pre> |
| 140 | StatCacheMaxAge 300 |
| 141 | </pre> |
| 142 | will cache successful <em>and</em> failed |
| 143 | <code>stat(2)</code>/<code>lstat(2)</code> calls for 5 minutes (300 seconds). |
| 144 | |
| 145 | <p> |
| 146 | To disable caching of failed <code>stat(2)</code>/<code>lstat(2)</code> calls |
| 147 | entirely, use a <em>negative-cache-age</em> value of zero, <i>e.g.</i>: |
| 148 | <pre> |
| 149 | # Cache lookups for 60 seconds, and do not cache failed lookups |
| 150 | StatCacheMaxAge 60 0 |
| 151 | </pre> |
| 152 | |
| 153 | <p> |
| 154 | <hr> |
| 155 | <h3><a name="StatCacheTable">StatCacheTable</a></h3> |
| 156 | <strong>Syntax:</strong> StatCacheTable <em>path</em><br> |
| 157 | <strong>Default:</strong> None<br> |
| 158 | <strong>Context:</strong> server config<br> |
| 159 | <strong>Module:</strong> mod_statcache<br> |
| 160 | <strong>Compatibility:</strong> 1.3.4rc2 and later |
| 161 | |
| 162 | <p> |
| 163 | The <code>StatCacheTable</code> directive configures a <em>path</em> to a file |
| 164 | that <code>mod_statcache</code> uses for handling its cache data. The given |
| 165 | <em>path</em> must be an absolute path. <b>Note</b>: this directive is |
| 166 | <b>required</b> for <code>mod_statcache</code> to function. It is recommended |
| 167 | that this file <b>not</b> be on an NFS mounted partition. |
| 168 | |
| 169 | <p> |
| 170 | Note that statcache data <b>is not</b> kept across daemon stop/starts. That is, |
| 171 | once <code>proftpd</code> is shutdown, all current statcache data is lost. |
| 172 | |
| 173 | <p> |
| 174 | <hr> |
| 175 | <h2>Control Actions</h2> |
| 176 | |
| 177 | <p> |
| 178 | <hr> |
| 179 | <h3><a name="statcache"><code>statcache</code></a></h3> |
| 180 | <strong>Syntax:</strong> ftpdctl statcache <em>info|dump</em><br> |
| 181 | <strong>Purpose:</strong> Display statcache information<br> |
| 182 | |
| 183 | <p> |
| 184 | The <code>statcache</code> action is used to display cache statistics about |
| 185 | the statcache data maintained by <code>mod_statcache</code>. For example: |
| 186 | <pre> |
| 187 | # ftpdctl statcache info |
| 188 | ftpdctl: hits 773, misses 67: 92.0% hit rate |
| 189 | ftpdctl: expires 22, rejects 0 |
| 190 | ftpdctl: current count: 1 (of 5000) (0.0% usage) |
| 191 | ftpdctl: highest count: 45 (of 5000) (0.9% usage) |
| 192 | </pre> |
| 193 | To dump out the entire cache contents (not recommended on a busy server), |
| 194 | you can use: |
| 195 | <pre> |
| 196 | # ftpdctl statcache dump |
| 197 | </pre> |
| 198 | |
| 199 | <p> |
| 200 | <hr> |
| 201 | <h2><a name="Installation">Installation</a></h2> |
| 202 | The <code>mod_statcache</code> module is distributed with ProFTPD. For |
| 203 | including <code>mod_statcache</code> as a statically linked module, use: |
| 204 | <pre> |
| 205 | $ ./configure --with-modules=mod_statcache |
| 206 | </pre> |
| 207 | To build <code>mod_statcache</code> as a DSO module: |
| 208 | <pre> |
| 209 | $ ./configure --enable-dso --with-shared=mod_statcache |
| 210 | </pre> |
| 211 | Then follow the usual steps: |
| 212 | <pre> |
| 213 | $ make |
| 214 | $ make install |
| 215 | </pre> |
| 216 | |
| 217 | <p> |
| 218 | For those with an existing ProFTPD installation, you can use the |
| 219 | <code>prxs</code> tool to add <code>mod_statcache</code>, as a DSO module, to |
| 220 | your existing server: |
| 221 | <pre> |
| 222 | $ prxs -c -i -d mod_statcache.c |
| 223 | </pre> |
| 224 | |
| 225 | <p> |
| 226 | <b>Note</b>: Use of the <code>mod_statcache</code> module <b>will</b> |
| 227 | interfere with the <code>mod_vroot</code> and <code>mod_quotatab</code> |
| 228 | modules. |
| 229 | |
| 230 | <p> |
| 231 | <hr> |
| 232 | <h2><a name="Usage">Usage</a></h2> |
| 233 | |
| 234 | <p> |
| 235 | The <code>mod_statcache</code> module works by allocating a SysV shared |
| 236 | memory segment. The different <code>proftpd</code> session processes |
| 237 | then attach to that shared memory segment so that they can share statcache |
| 238 | results. |
| 239 | |
| 240 | <p> |
| 241 | Example configuration: |
| 242 | <pre> |
| 243 | <IfModule mod_statcache.c> |
| 244 | StatCacheEngine on |
| 245 | StatCacheTable /var/run/proftpd/statcache.tab |
| 246 | </IfModule> |
| 247 | </pre> |
| 248 | |
| 249 | <p> |
| 250 | <hr> |
| 251 | <font size=2><b><i> |
| 252 | © Copyright 2013-2017 TJ Saunders<br> |
| 253 | All Rights Reserved<br> |
| 254 | </i></b></font> |
| 255 | <hr> |
| 256 | |
| 257 | </body> |
| 258 | </html> |