Monday, October 18, 2004

Optimize your ISAPI Dlls - Increase MaxConnections!

When your web application is called (as an ISAPI, NSAPI or Apache module), the Application spawns a new thread for a request. Within the context of this thread, your main web module is create.

When the request is handled and response is sent, the created instance is then:

  • Freed, if you set Application.CacheConnections=False. (It's true by default)
  • If Cache Connections is true, then the webmodule is cached in an internal array for reuse at the next request.

Setting CacheConnections to false will create a webmodule for each request - something we don't want, unless there's a real reason for doing so. So let's keep CacheConnections on. But, what if you have one request being handled when another request comes in? The application will look inside the cache - if a webmodule is available, it is used. Otherwise a new thread is created, with a new instance of a the webmodule is created to handle the request. This happens until the number of currently active connections reaches the value in Application.MaxConnections, after which an exception is raised which says "Too many active connections". This shows up as an Internal Server Error on the browser.

Now the default for Application.MaxConnections is 32 - so if you have any more than 32 connections active at any time, you will see internal server errors. 32 is woefully inadequate for anything that's in production, so you must increase this number - but do remember to test the "before" and "after" because at some point your memory usage will trade off against performance.

Note: All you have to do is set Application.MaxConnections in your .dpr file.

0 Comments:

Post a Comment

<< Home