You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by rj...@apache.org on 2008/09/28 11:41:53 UTC
svn commit: r699791 -
/tomcat/connectors/branches/other/jk_isapi_plugin_chunked/jk/native/iis/jk_isapi_plugin.c
Author: rjung
Date: Sun Sep 28 02:41:53 2008
New Revision: 699791
URL: http://svn.apache.org/viewvc?rev=699791&view=rev
Log:
Add heuristics to determine adequate default size
of connection pool.
Disabled by default, enabled via define AUTOMATIC_POOL_SIZE.
Modified:
tomcat/connectors/branches/other/jk_isapi_plugin_chunked/jk/native/iis/jk_isapi_plugin.c
Modified: tomcat/connectors/branches/other/jk_isapi_plugin_chunked/jk/native/iis/jk_isapi_plugin.c
URL: http://svn.apache.org/viewvc/tomcat/connectors/branches/other/jk_isapi_plugin_chunked/jk/native/iis/jk_isapi_plugin.c?rev=699791&r1=699790&r2=699791&view=diff
==============================================================================
--- tomcat/connectors/branches/other/jk_isapi_plugin_chunked/jk/native/iis/jk_isapi_plugin.c (original)
+++ tomcat/connectors/branches/other/jk_isapi_plugin_chunked/jk/native/iis/jk_isapi_plugin.c Sun Sep 28 02:41:53 2008
@@ -52,19 +52,26 @@
#include <strsafe.h>
#ifdef ALLOW_CHUNKING
-#define SUFFIX "-CHUNKING"
+#define HAS_CHUNKING "-CHUNKING"
#else
-#define SUFFIX "-NO_CHUNKING"
+#define HAS_CHUNKING "-NO_CHUNKING"
#endif
-#define VERSION_STRING "Jakarta/ISAPI/" JK_EXPOSED_VERSION SUFFIX
+#ifdef AUTOMATIC_POOL_SIZE
+#define HAS_AUTO_POOL "-AUTO_POOL"
+#else
+#define HAS_AUTO_POOL "-NO_AUTO_POOL"
+#endif
+#define VERSION_STRING "Jakarta/ISAPI/" JK_EXPOSED_VERSION HAS_CHUNKING HAS_AUTO_POOL
#define SHM_DEF_NAME "JKISAPISHMEM"
#define DEFAULT_WORKER_NAME ("ajp13")
+#ifndef AUTOMATIC_POOL_SIZE
/*
* This is default value found inside httpd.conf
* for MaxClients
*/
#define DEFAULT_WORKER_THREADS 250
+#endif
/*
* We use special headers to pass values from the filter to the
@@ -305,6 +312,12 @@
static int read_registry_init_data(void);
+#ifdef AUTOMATIC_POOL_SIZE
+static int read_registry_pool_thread_limit(size_t *pool_threads);
+
+static int determine_iis_thread_count();
+
+#endif
static int get_config_parameter(LPVOID src, const char *tag,
char *val, DWORD sz);
@@ -2039,10 +2052,113 @@
return 0;
}
+#ifdef AUTOMATIC_POOL_SIZE
+static int read_registry_pool_thread_limit(size_t *pool_threads)
+{
+#define IIS_PARAMETERS_LOCATION ("SYSTEM\\CurrentControlSet\\Services\\InetInfo\\Parameters")
+#define IIS_MAX_POOL_THREADS_KEY ("PoolThreadLimit")
+
+ HKEY hkey;
+ int rc = JK_FALSE;
+ DWORD regPtl;
+
+ JK_TRACE_ENTER(logger);
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "Checking registry for PoolThreadLimit override." );
+ }
+ rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
+ IIS_PARAMETERS_LOCATION, (DWORD) 0, KEY_READ, &hkey);
+
+ if (ERROR_SUCCESS != rc) {
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "Unable to open registry for reading." );
+ }
+ JK_TRACE_EXIT(logger);
+ return JK_FALSE;
+ }
+
+ if (get_registry_config_number(hkey, IIS_MAX_POOL_THREADS_KEY, ®Ptl )) {
+ (*pool_threads) = (unsigned)regPtl;
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "PoolThreadLimit override of %d located in registry.",
+ (*pool_threads) );
+ }
+ rc = JK_TRUE;
+ } else {
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "PoolThreadLimit setting not found in registry." );
+ }
+ rc = JK_FALSE;
+ }
+
+ RegCloseKey( hkey );
+
+ JK_TRACE_EXIT(logger);
+ return rc;
+}
+
+static int determine_iis_thread_count()
+{
+#define CACHE_SIZE_WORKSTATION 10
+ OSVERSIONINFOEX verinfo;
+ size_t cache_size;
+
+ JK_TRACE_ENTER(logger);
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "Attempting to set connection_pool_size to suit current OS settings." );
+ }
+
+ /* Check the type of OS we're using */
+ ZeroMemory(&verinfo, sizeof(OSVERSIONINFOEX));
+ verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
+ if (GetVersionEx((LPOSVERSIONINFO)(&verinfo))) {
+ /* For Server OSes, determine PoolThreadLimit */
+ if (verinfo.wProductType == VER_NT_DOMAIN_CONTROLLER || verinfo.wProductType == VER_NT_SERVER) {
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "Current OS detected as Server OS - will try to detect PoolThreadLimit" );
+ }
+
+ /* Check in the registry first for an override */
+ if (!read_registry_pool_thread_limit( &cache_size )) {
+ /* Otherwise, Calculate default cache size as 2*MB RAM, capped at 256 */
+ MEMORYSTATUS memstat;
+ GlobalMemoryStatus(&memstat);
+ cache_size = 2 * memstat.dwTotalPhys / (1024*1024);
+ if (cache_size > 256 )
+ cache_size = 256;
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "PoolThreadLimit not in registry - "
+ "calculating default connection_pool_size of MIN(2*MB,256) as %u",
+ cache_size );
+ }
+ }
+ } else {
+ /* We have a Workstation/Pro version running PWS */
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "Current OS is a Workstation/Pro - "
+ "using PWS connection_pool_size of %d",
+ CACHE_SIZE_WORKSTATION );
+ }
+ cache_size = CACHE_SIZE_WORKSTATION;
+ }
+ } else {
+ /* Assume Workstation - something is probably wrong here */
+ jk_log(logger, JK_LOG_WARNING, "Unable to detect current OS - assuming Workstation/Pro - "
+ "using PWS connection_pool_size of %d", CACHE_SIZE_WORKSTATION );
+ cache_size = CACHE_SIZE_WORKSTATION;
+ }
+ JK_TRACE_EXIT(logger);
+ return (int)cache_size;
+}
+#endif
+
static int init_jk(char *serverName)
{
char shm_name[MAX_PATH];
int rc = JK_FALSE;
+#ifdef AUTOMATIC_POOL_SIZE
+ int def_cache_size;
+#endif
if (!jk_open_file_logger(&logger, log_file, log_level)) {
logger = NULL;
@@ -2062,7 +2178,18 @@
}
}
+#ifdef AUTOMATIC_POOL_SIZE
+ def_cache_size = determine_iis_thread_count();
+ if (JK_IS_DEBUG_LEVEL(logger)) {
+ jk_log(logger, JK_LOG_DEBUG, "Setting default connection_pool_size to %u",
+ def_cache_size );
+ }
+ jk_set_worker_def_cache_size(def_cache_size);
+ jk_log(logger, JK_LOG_INFO, "Using a default of %d connections per pool",
+ def_cache_size);
+#else
jk_set_worker_def_cache_size(DEFAULT_WORKER_THREADS);
+#endif
/* Logging the initialization type: registry or properties file in virtual dir
*/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org