You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Chirouze Olivier <ol...@volvo.com> on 2007/02/16 16:03:21 UTC

[users@httpd] RE: Trying to limit connections per virtual host with mod_cband [** FIXED with mod_vhost_limit **]

Hi all.

This is the full story with... FIX! :-)

Let me try to make a good "googleable" summary (it took me so much time
to sort this out, I'd be happy if someone finds it useful).

The story begins like this: I was trying to limit the number of
simultaneous connections per virtualhost on Apache 2.0.58 running as a
reverse proxy.
1) Apache doesn't allow to limit simultaneous connections per
virtualhost (MaxClient only works at server level).
2) A few modules exist, but I never managed to have them working with
[reverse] proxy. => they only worked when Apache is working as a web
server.

What I realized was quite simple, but so sad: the modules were called
AFTER mod proxy. Which makes them useless!

Thanks to the only answer I had on the forum (thanks a lot to Joshua
Slive), I found solutions to change the order in which modules are
called.

I never managed to make mod_cband work (never managed to contact the
developer either), but by hacking mod_vhost_limit, that finally worked.

All modules register to Apache using the following function:

static void register_hooks(apr_pool_t *p)
{
    ap_hook_handler(vhost_limit_handler, NULL, NULL,
APR_HOOK_REALLY_FIRST);//APR_HOOK_MIDDLE);
    ap_hook_post_config(vhost_limit_init, NULL, NULL,
APR_HOOK_REALLY_FIRST);//APR_HOOK_MIDDLE);
}

Last parameter says "load this module somewhere". Changing
APR_HOOK_MIDDLE to APR_HOOK_FIRST would have been too easy: mod_proxy
allready says "I'm first" with this value!! Then I found the magic
"APR_HOOK_REALLY_FIRST" that finally made the module loaded first. I
guess next version of Apache will get the "APR_HOOK_REALLY_REALLY_FIRST"
value, and so on :-)

I can now limit the number of simultaneous connections per virtualhost,
before they are forwarded to the webserver by mod proxy.

I'm happy.

Olivier

PS: I will try to contact mod_vhost_limit creator to share the hacking.
Open source rules ;-)

Olivier CHIROUZE
I&0 Infrastructure
Volvo Information Technology
 

> -----Original Message-----
> From: Chirouze Olivier 
> Sent: 09 February 2007 17:08
> To: 'users@httpd.apache.org'
> Subject: Trying to limit connections per virtual host with mod_cband
> 
> Hi,
> 
> I'm trying to use mod_cband... but can't manage to!
> 
> I've tailed down my conf file to the most simple case with 
> just one virtual host.
> What I'm trying to achieve is quite simple: I just want to 
> limit the number of concurrent connections per virtual host 
> (a "MaxClient" at the virtualhost level) and I think this is 
> one of the many features of cband.
> 
> How do I test this? Just call multiple times a page that 
> takes very long to anwser: during all this time, for each 
> click, a connection on this virtual host stays open on 
> Apache. (thanks a lot to Georgi Chorbadzhiyski for pointing 
> me to /status?notable that proves the connections are open on 
> the right virtual host).
> 
> The thing is, on cband-status, I see some rps used, but never 
> a single connection! (thanks to cband status page: 
> /cband-status). "Current connection" always stays at 0. And, 
> in fact, the limit is never used. I set it to 2 and can have 
> more than 10 concurrent connections. So, in a word, it 
> doesn't work as expected.
> 
> However, I see some "remote client", but always one. The 
> virtual host is correct, but "Connections Limit/Current" 
> always says "1/0". I don't understand how a line can be here 
> with zero connection?
> 
> I'm kind of lost after looking around for days and trying all 
> I can think of (simplifying the config file, unactivating 
> modules, changing order of LoadModule, using OpenSta, etc...)
> 
> I'm using mod_rewrite and mod_proxy and I think that might be 
> the pb. But there is an example with mod_rewrite on cband 
> homepage so I suppose there is no incompatibility!
> 
> Please... Help ;-)
> 
> Olivier
> 
> Olivier CHIROUZE
> I&0 Infrastructure
> 
> The conf file:
> --------------------------------------------------------------
> ------------------------------------------
> 
> ServerRoot /data/apache/httpd-test1
> 
> # This only contains standard httpd.conf file with the 
> following modules activated:
> #LoadModule access_module modules/mod_access.so
> #LoadModule log_config_module modules/mod_log_config.so
> #LoadModule logio_module modules/mod_logio.so
> #LoadModule env_module modules/mod_env.so
> #LoadModule setenvif_module modules/mod_setenvif.so
> #LoadModule ssl_module modules/mod_ssl.so
> #LoadModule mime_module modules/mod_mime.so
> #LoadModule status_module modules/mod_status.so
> #LoadModule negotiation_module modules/mod_negotiation.so
> #LoadModule dir_module modules/mod_dir.so
> #LoadModule alias_module modules/mod_alias.so
> Include 
> /data/apache/httpd-test1/appli-apache/conf/httpd_solaris28.conf
> 
> ServerName  reverse-proxy-test2.iteu.volvo.net
> 
> User apache
> Group apache
> 
> DocumentRoot "/data/apache/httpd-test1/htdocs"
> 
> ServerAdmin apache@reverse-proxy-test2.iteu.volvo.net
> 
> LoadModule cband_module choucroutemodules/mod_cband.so
> 
> LoadModule proxy_module modules/mod_proxy.so
> 
> LoadModule proxy_http_module modules/mod_proxy_http.so
> 
> CustomLog /logs/apache/httpd-test1/logs/rproxy_log "%{Host}i 
> |%{RULE}e| %{%H/%T}t %h -> %{SERVER}e URL: %U"
> 
> UseCanonicalName Off
> 
> <VirtualHost reverse-proxy-test2.iteu.volvo.net:80>
> 	<Location /status>
> 		SetHandler server-status
> 		Order deny,allow
> 		Allow from all
> 	</Location>
> 	<Location /info>
> 	    SetHandler server-info
> 	</Location>
> </VirtualHost>
> 
> LoadModule rewrite_module     modules/mod_rewrite.so
> 
> RewriteEngine on
> RewriteLog	/logs/apache/httpd-test1/logs/rewrite_log
> RewriteLogLevel 0
> 
> LogLevel debug
> 
> Listen		reverse-proxy-test2.iteu.volvo.net:80
> NameVirtualHost reverse-proxy-test2.iteu.volvo.net:80
> 
> <IfModule mod_cband.c>
> 	<Location /cband-status>
> 		SetHandler cband-status
> 		Order deny,allow
> 		Allow from all
> 	</Location>
> 	<Location /cband-status-me>
> 		SetHandler cband-status-me
> 		Order deny,allow
> 		Allow from all
> 	</Location>
> </IfModule>
> 
> <IfModule mod_cband.c>
>         CBandSpeed 0 0 10
> 	CBandScoreFlushPeriod 1
> 	CBandRandomPulse On
> </IfModule>
> 
> <VirtualHost reverse-proxy-test2.iteu.volvo.net:80>
> ServerName      youpi.volvo.net
> 
> <IfModule mod_cband.c>
>         CBandRemoteSpeed 0 3 1
>         CBandSpeed 0 0 2
>         CBandDefaultExceededCode 503
>         CBandScoreboard /tmp/apache/scoreboard
>         CBandPeriod 2s
> </IfModule>
> 
> RewriteEngine   on
> RewriteLog      /logs/apache/httpd-test1/logs/rewrite_log
> RewriteLogLevel 3
> Include         conf/deny_patterns.conf
> 
> RewriteRule     ^/(.*)$ http://10.213.131.69/waitZoub.php?wait=$1 [P]
> 
> ProxyRequests   off
> 
> KeepAlive Off
> 
> </VirtualHost>

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org