⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tuning.xtp

📁 解压在c盘
💻 XTP
字号:
<s1 title="Performance Tuning"><summarylist/><s2 title="Resin Threads"><p>Resin will automatically allocate and free threads as the load requires.Since the threads are pooled, Resin can reuse old threads without theperformance penalty of creating and destroying the threads.  When theload drops, Resin will slowly decrease the number of threads in thepool until is matches the load.</p><p>Most users can set <var/thread-max/> to something large (200 orgreater) and then forget about the threading.  Some ISPs dedicate aJVM per user and have many JVMs on the same machine.  In that case, itmay make sense to reduce the <var/thread-max/> to throttle therequests.</p><p>Since each servlet request gets its own thread, <var/thread-max/>determines the maximum number of concurrent users.  So if you have apeak of 100 users with slow modems downloading a large file, you'llneed a <var/thread-max/> of at least 100.  The number of concurrentusers is unrelated to the number of active sessions.  Unless the useris actively downloading, he doesn't need a thread (except for "keepalives").</p></s2><s2 title="Keepalives"><p>Keepalives make HTTP and srun requests more efficient.  Connecting toa TCP server is relatively expensive.  The client and server need tosend several packets back and forth to establish the connection beforethe first data can go through.  HTTP/1.1 introduced a protocol to keepthe connection open for more requests.  The srun protocol betweenResin and the web server plugin also uses keepalives.  By keeping theconnection open for following requests, Resin can improve performance.</p><p>But keepalive connections tie up a Resin thread waiting for thenext client request.  So the number of keepalive threads needs to belower than the maximum number of threads.  In the resin.conf,<var/thread-keepalive/> must be less than <var/thread-max/>.  It's a goodidea to have a gap of at least 50 between the two.  The followingmight be a typical configuration:</p><example title='resin.conf for thread-keepalive'>...&lt;thread-max>250&lt;/thread-max>&lt;thread-keepalive>150&lt;/thread-keepalive>...</example><p>In the above case, at most 150 clients can have an open connectioneven if they're not doing anything.  That still leaves 100 threadsaccepting new connections.  Note, these keepalives also apply to theweb server plugin using the srun protocol.  So <var/thread-keepalive/>will limit the number of Apache/mod_caucho connections thatare left open.</p><s3 title="Timeouts"><p>Requests and keepalive connections can only be idle for a limitedtime before Resin closes them.  Each connection has a readtimeout, <var/request-timeout/>.  If the client doesn't send a requestwithin the timeout, Resin will close the TCP socket.  The timeoutprevents idle clients from hogging Resin resources.</p><example>...&lt;thread-max>250&lt;/thread-max>&lt;thread-keepalive>150&lt;/thread-keepalive>&lt;request-timeout>30&lt;/request-timeout>&lt;live-time>20&lt;/live-time>...</example><p>In general, the request-timeout and keepalives are less importantfor Resin standalone configurations than Apache/IIS/srunconfigurations.  Very heavy traffic sites may want to reduce thetimeout for Resin standalone.</p><p>Since <var/request-timeout/> will close srun connections, itssetting needs to take into consideration the <var/live-time/> settingfor mod_caucho or isapi_srun.  <var/live-time/> is the time theplugin will keep a connection open.  <var/request-timeout/> mustalways be larger than <var/live-time/>, otherwise the plugin will tryto reuse a closed socket.</p></s3><s3 title="Plugin keepalives (mod_caucho/isapi_srun)"><p>The web server plugin, mod_caucho, needs configuration for its keepalivehandling because requests are handled differently in the web server.Until the web server sends a request to Resin, it can't tell if Resinhas closed the other end of the socket.  If the JVM has restartedor if closed the socket because of <var/request-timeout/>,mod_caucho will not know about the closed socket.  So mod_caucho needsto know how long to consider a connection reusable before closing it.<var/live-time/> tells the plugin how long it should consider asocket usable.</p><p>Because the plugin isn't signalled when Resin closes the socket,the socket will remain half-closed until the next web server request.A <var/netstat/> will show that as a bunch of sockets in the FIN_WAIT_2state.  With Apache, there doesn't appear to be a good way aroundthis.  If these become a problem, you can increase<var/request-timeout/> and <var/live-time/> so the JVM won't close thekeepalive connections as fast.</p><example>unix> netstat...localhost.32823      localhost.6802       32768      0 32768      0 CLOSE_WAITlocalhost.6802       localhost.32823      32768      0 32768      0 FIN_WAIT_2localhost.32824      localhost.6802       32768      0 32768      0 CLOSE_WAITlocalhost.6802       localhost.32824      32768      0 32768      0 FIN_WAIT_2...</example></s3><s3 title="TCP limits (TIME_WAIT)"><p>A client and a server that open a large number of TCP connections canrun into operating system/TCP limits.  If mod_caucho isn't configuredproperly, it can use too many connections to Resin.  When the limit isreached, mod_caucho will report "can't connect" errors until a timeoutis reached.  Load testing or benchmarking can run into the samelimits, causing apparent connection failures even though the Resinprocess is running fine.</p><p>The TCP limit is the TIME_WAIT timeout.  When the TCP socketcloses, the side starting the close puts the socket into the TIME_WAITstate.  A <var/netstat/> will short the sockets in the TIME_WAITstate.  The following shows an example of the TIME_WAIT socketsgenerated while benchmarking.  Each client connection has a uniqueephemeral port and the server always uses its public port:</p><example title='Typical Benchmarking Netstat'>unix> netstat...tcp   0   0 localhost:25033  localhost:8080  TIME_WAIT   tcp   0   0 localhost:25032  localhost:8080  TIME_WAIT   tcp   0   0 localhost:25031  localhost:8080  TIME_WAIT   tcp   0   0 localhost:25030  localhost:8080  TIME_WAIT   tcp   0   0 localhost:25029  localhost:8080  TIME_WAIT   tcp   0   0 localhost:25028  localhost:8080  TIME_WAIT...</example><p>The socket will remain in the TIME_WAIT state for asystem-dependent time, generally 120 seconds, but usuallyconfigurable.  Since there are less than 32k ephemeral socket available tothe client, the client will eventually run out and start seeingconnection failures.  On some operating systems, including RedHatLinux, the default limit is only 4k sockets.  The full 32k socketswith a 120 second timeout limits the number of connections to about250 connections per second.</p><p>If mod_caucho or isapi_srun are misconfigured, they can use toomany connections and run into the TIME_WAIT limits.  Using keepaliveseffectively avoids this problem.  Since keepalive connections arereused, they won't go into the TIME_WAIT state until they're finallyclosed.  A site can maximize the keepalives by setting<var/thread-keepalive/> large and setting <var/live-time/> and<var/request-timeout/> to large values.  <var/thread-keepalive/> limitsthe maximum number of keepalive connections.  <var/live-time/> and<var/request-timeout/> will configure how long the connection will bereused.</p><example title='Configuration for a medium-loaded Apache'>...&lt;thread-max>250&lt;/thread-max>&lt;thread-keepalive>200&lt;/thread-keepalive>&lt;request-timeout>120&lt;/request-timeout>&lt;live-time>100&lt;/live-time>...</example><p><var/thread-max/> must always be larger than <var/thread-keepalive/>and <var/request-timeout/> must always be larger than<var/live-time/>.  In addition, <var/thread-keepalive/> should be largerthan the maximum number of Apache processes.</p></s3><s3 title="Apache issues"><p>Using Apache as a web server on Unix introduces a number of issues becauseApache uses a process model instead of a threading model.  The Apacheprocesses don't share the keepalive srun connections.  Each processhas its own connection to Resin.  In contrast, IIS uses a threadedmodel so it can share Resin connections between the threads.  TheApache process model means Apache needs more connections to Resin thana threaded model would.</p><p>In other words, the keepalive and TIME_WAIT issues mentioned aboveare particularly important for Apache web servers.  It's a good ideato use <var/netstat/> to check that a loaded Apache web server isn'trunning out of keepalive connections and running into TIME_WAIT problems.</p></s3></s2></s1>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -