1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Draft//EN">
<HTML>
<HEAD>
<TITLE>SQUID Frequently Asked Questions: DISKD</TITLE>
</HEAD>
<BODY>
<A HREF="FAQ-23.html">Next</A>
<A HREF="FAQ-21.html">Previous</A>
<A HREF="FAQ.html#toc22">Contents</A>
<HR>
<H2><A NAME="s22">22. DISKD</A></H2>
<H2><A NAME="ss22.1">22.1 What is DISKD?</A>
</H2>
<P>DISKD refers to some features in Squid-2.4 to improve Disk I/O performance.
The basic idea is that each <EM>cache_dir</EM> has its own <EM>diskd</EM> child process.
The diskd process performs all disk I/O operations (open, close, read, write, unlink)
for the cache_dir. Message queues are used to send requests and responses between
the Squid and diskd processes. Shared memory is used for chunks of data to
be read and written.
<P>
<H2><A NAME="ss22.2">22.2 Does it perform better?</A>
</H2>
<P>Yes. We benchmarked Squid-2.4 with DISKD at the
<A HREF="http://polygraph.ircache.net/Results/bakeoff-2/">Second IRCache Bake-Off</A>.
The results are also described
<A HREF="/Benchmarking/bakeoff-02/">here</A>.
At the bakeoff, we got 160 req/sec with diskd. Without diskd, we'd have gotten about 40 req/sec.
<P>
<H2><A NAME="ss22.3">22.3 What do I need to use it?</A>
</H2>
<P>
<OL>
<LI>Squid-2.4</LI>
<LI>Your operating system must support message queues.</LI>
<LI>Your operating system must support shared memory.</LI>
</OL>
<P>
<H2><A NAME="ss22.4">22.4 If I use DISKD, do I have to wipe out my current cache?</A>
</H2>
<P>No. Diskd uses the same storage scheme as the standard "UFS"
type. It only changes how I/O is performed.
<P>
<H2><A NAME="ss22.5">22.5 How do I configure message queues?</A>
</H2>
<P>Most Unix operating systems have message queue support
by default. One way to check is to see if you have
an <EM>ipcs</EM> command.
<P>
<P>However, you will likely need to increase the message
queue parameters for Squid. Message queue implementations
normally have the following parameters:
<DL>
<DT><B>MSGMNB</B><DD><P>Maximum number of bytes in a single queue.
<DT><B>MSGMNI</B><DD><P>Maximum number of message queue identifiers.
<DT><B>MSGSEG</B><DD><P>Maximum number of message segments.
<DT><B>MSGMAX</B><DD><P>Maximum size of a message segment.
<DT><B>MSGTQL</B><DD><P>Maximum number of messages in the whole system.
</DL>
<P>
<P>The messages between Squid and diskd are 32 bytes. Thus, MSGMAX
should be 32 or greater. You may want to set it to a larger
value, just to be safe.
<P>
<P>We'll have two queues for each <EM>cache_dir</EM> -- one in each direction.
So, MSGMNI needs to be at least two times the number of <EM>cache_dir</EM>'s.
<P>
<P>MSGMNB and MSGTQL affect how many messages can be in the queues
at one time. I've found that 75 messages per queue is about
the limit of decent performance. Thus, MSGMNB must be
at least 75*MSGMAX, and MSGTQL must be at least 75 times
the number of <EM>cache_dir</EM>'s.
<P>
<H3>FreeBSD</H3>
<P>Your kernel must have
<PRE>
options SYSVMSG
</PRE>
<P>
<P>You can set the parameters in the kernel as follows. This is just
an example. Make sure the values are appropriate for your system:
<PRE>
options MSGMNB=16384 # max # of bytes in a queue
options MSGMNI=41 # number of message queue identifiers
options MSGSEG=2049 # number of message segments
options MSGSSZ=64 # size of a message segment
options MSGTQL=512 # max messages in system
</PRE>
<P>
<H3>Digital Unix</H3>
<P>Message queue support seems to be in the kernel
by default. Setting the options is as follows:
<PRE>
options MSGMNB="8192" # max # bytes on queue
options MSGMNI="31" # # of message queue identifiers
options MSGMAX="2049" # max message size
options MSGTQL="1024" # # of system message headers
</PRE>
<P>
<P>by
<A HREF="mailto:B.C.Phillips at massey dot ac dot nz">Brenden Phillips</A><P>If you have a newer version (DU64), then you can probably use
<EM>sysconfig</EM> instead. To see what the current IPC settings are run
<PRE>
# sysconfig -q ipc
</PRE>
To change them make a file like this called ipc.stanza:
<PRE>
ipc:
msg-max = 2049
msg-mni = 31
msg-tql = 1024
msg-mnb = 8192
</PRE>
then run
<PRE>
# sysconfigdb -a -f ipc.stanza
</PRE>
You have to reboot for the change to take effect.
<P>
<P>
<P>
<H3>Linux</H3>
<P>In my limited browsing on Linux, I didn't see any way to change
message queue parameters except to modify the include files
and build a new kernel. On my system, the file
is <EM>/usr/src/linux/include/linux/msg.h</EM>.
<P>
<H3>Solaris</H3>
<P>Refer to
<A HREF="http://www.sunworld.com/sunworldonline/swol-11-1997/swol-11-insidesolaris.html">Demangling Message Queues</A> in Sunworld Magazine.
<P>
<P>I don't think the above article really tells you how to set the parameters.
You do it in <EM>/etc/system</EM> with lines like this:
<PRE>
set msgsys:msginfo_msgmax=2049
set msgsys:msginfo_msgmnb=8192
set msgsys:msginfo_msgmni=31
set msgsys:msginfo_msgssz=64
set msgsys:msginfo_msgtql=1024
</PRE>
<P>Of course, you must reboot whenever you modify <EM>/etc/system</EM>
before changes take effect.
<P>
<H2><A NAME="ss22.6">22.6 How do I configure shared memory?</A>
</H2>
<P>Shared memory uses a set of parameters similar to the ones for message
queues. The Squid DISKD implementation uses one shared memory area
for each cache_dir. Each shared memory area is about
800 kilobytes in size. You may need to modify your system's
shared memory parameters:
<P>
<P>
<DL>
<DT><B>SHMSEG</B><DD><P>Maximum number of shared memory segments per process.
<DT><B>SHMMNI</B><DD><P>Maximum number of shared memory segments for the whole system.
<DT><B>SHMMAX</B><DD><P>Largest shared memory segment size allowed.
<DT><B>SHMALL</B><DD><P>Total amount of shared memory that can be used.
</DL>
<P>
<P>For Squid and DISKD, <EM>SHMMNI</EM> and <EM>SHMMNI</EM> must be greater than
or equal to the number of <EM>cache_dir</EM>'s that you have. <EM>SHMMAX</EM>
must be at least 800 kilobytes. <EM>SHMALL</EM> must be at least
<EM>SHMMAX</EM> 800 kilobytes multiplied by the number of <EM>cache_dir</EM>'s.
<P>
<H3>FreeBSD</H3>
<P>Your kernel must have
<PRE>
options SYSVSHM
</PRE>
<P>
<P>You can set the parameters in the kernel as follows. This is just
an example. Make sure the values are appropriate for your system:
<PRE>
options SHMSEG=16 # max shared mem id's per process
options SHMMNI=32 # max shared mem id's per system
options SHMMAX=2097152 # max shared memory segment size (bytes)
options SHMALL=4096 # max amount of shared memory (pages)
</PRE>
<P>
<H3>Digital Unix</H3>
<P>Message queue support seems to be in the kernel
by default. Setting the options is as follows:
<PRE>
options SHMSEG="16" # max shared mem id's per process
options SHMMNI="32" # max shared mem id's per system
options SHMMAX="2097152" # max shared memory segment size (bytes)
options SHMALL=4096 # max amount of shared memory (pages)
</PRE>
<P>
<P>by
<A HREF="mailto:B.C.Phillips at massey dot ac dot nz">Brenden Phillips</A><P>If you have a newer version (DU64), then you can probably use
<EM>sysconfig</EM> instead. To see what the current IPC settings are run
<PRE>
# sysconfig -q ipc
</PRE>
To change them make a file like this called ipc.stanza:
<PRE>
ipc:
shm-seg = 16
shm-mni = 32
shm-max = 2097152
shm-all = 4096
</PRE>
then run
<PRE>
# sysconfigdb -a -f ipc.stanza
</PRE>
You have to reboot for the change to take effect.
<P>
<P>
<H3>Linux</H3>
<P>In my limited browsing on Linux, I didn't see any way to change
shared memory parameters except to modify the include files
and build a new kernel. On my system, the file
is <EM>/usr/src/linux/include/asm-i386/shmparam.h</EM>
<P>
<P>Oh, it looks like you can change <EM>SHMMAX</EM> by writing
the file <EM>/proc/sys/kernel/shmmax</EM>.
<P>
<H3>Solaris</H3>
<P>Refer to
<A HREF="http://www.sunworld.com/swol-09-1997/swol-09-insidesolaris.html">Shared memory uncovered</A>
in Sunworld Magazine.
<P>
<P>To set the values, you can put these lines in <EM>/etc/system</EM>:
<PRE>
set shmsys:shminfo_shmmax=2097152
set shmsys:shminfo_shmmni=32
set shmsys:shminfo_shmseg=16
</PRE>
<P>
<H2><A NAME="ss22.7">22.7 Sometimes shared memory and message queues aren't released when Squid exits.</A>
</H2>
<P>Yes, this is a little problem sometimes. Seems like the operating system
gets confused and doesn't always release shared memory and message
queue resources when processes exit, especially if they exit abnormally.
To fix it you can ``manually'' clear the resources with the <EM>ipcs</EM> command.
Add this command into your <EM>RunCache</EM> or <EM>squid_start</EM>
script:
<PRE>
ipcs | grep '^[mq]' | awk '{printf "ipcrm -%s %s\n", $1, $2}' | /bin/sh
</PRE>
<P>
<H2><A NAME="ss22.8">22.8 What are the Q1 and Q2 parameters?</A>
</H2>
<P>In the source code, these are called <EM>magic1</EM> and <EM>magic2</EM>.
These numbers refer to the number of oustanding requests on a message
queue. They are specified on the <EM>cache_dir</EM> option line, after
the L1 and L2 directories:
<PRE>
cache_dir diskd -1 /cache1 1024 16 256 64 72
</PRE>
<P>If there are more than Q1 messages outstanding, then the main Squid
process ``blocks'' for a little bit until the diskd process services
some of the messages and sends back some replies.
<P>If there are more than Q2 messages outstanding, then Squid will
intentionally fail to open disk files for reading and writing.
This is a load-shedding mechanism. If your cache gets really really
busy and the disks can not keep up, Squid bypasses the disks until
the load goes down again.
<P>Reasonable values for Q1 and Q2 are 64 and 72, respectively.
<P>
<P>
<HR>
<A HREF="FAQ-23.html">Next</A>
<A HREF="FAQ-21.html">Previous</A>
<A HREF="FAQ.html#toc22">Contents</A>
</BODY>
</HTML>
|