apache2buddy icon indicating copy to clipboard operation
apache2buddy copied to clipboard

apache2buddy not considering vcache

Open bitfoo1 opened this issue 7 years ago • 39 comments

Hello,

first thank you for your effort writing this tool. It helps me allot. I used it today on our heavily loaded web servers with Apache2 and Varnish. It is a 32Gb memory instance. I configured varnish (vcache) to cache all our requests on the instance. I tried to figure out how many workers I can spawn. So I issued apache2buddy.pl and it outputs following varnish line: [ -- ] Varnish Detected => Using 7.44 MB of memory. but this is only varnish and not its vcache. I configure Varnish (vcache) to use 16Gb memory. Maybe it would be better du substract den configured vcache from the total memory to make better recommendations.

bitfoo1 avatar Jan 07 '19 21:01 bitfoo1

Hi Apache2buddy only detects what is actually being used by additional services, it doesnt care what you configured it to use. If I am not detecting the usage of the vcache, in ps output, please provide an example of how I can detect this (note that parsing any configuration files is not an option).

richardforth avatar Jan 08 '19 09:01 richardforth

Hi @richardforth, I found a way to find the memory consumption of the vcache. The problem is it is not the command as you use in your code with -C for ps. The cache is owned by the user vcache. I issued following command to get its complete ps output

ps aux | grep vcache vcache 27009 30.7 58.5 29486828 18815824 ? Sl Jan07 408:01 /usr/sbin/varnishd -a :6081 -T 127.0.0.1:6082 -P /run/varnishd.pid -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,16G

So that I now know what to filter I use following command to get its actually used mem

ps -U vcache -o rss | grep -v RSS 18759136

Hope this solution is good to implement.

bitfoo1 avatar Jan 08 '19 13:01 bitfoo1

Unfortunately for me this isnt making much sense, as the stock installations of varnish show up just fine in ps -C as we are only interested in processes running called varnishd , so it should be picking up your /usr/sbin/varnishd process no matter the fact that its running as a user called vcache.

Can you run the following for me and let me know what you get back:

# ps auxfwww | grep varnishd

# ps -C varnishd

# pc -C varnishd -o rss | grep -v RSS

Also if you can, run apache2buddy.pl in verbose mode and get me the varnish ouput:

# curl -sL https://raw.githubusercontent.com/richardforth/apache2buddy/master/apache2buddy.pl | perl - --verbose | grep -i varnish

Hopefully I will be able to make sense of whats gong on

richardforth avatar Jan 08 '19 14:01 richardforth

I issued following

# perl apache2buddy.pl --verbose | grep -i varnish
VERBOSE: Varnish Detected
[ -- ] Varnish Detected => Using 7.25 MB of memory.
VERBOSE: Varnish Mem: 7.25

I also issue following

# ps aux | grep -i varnish
root     12846  0.0  0.0  13096   940 pts/2    S+   14:34   0:00 grep --color=auto -i varnish
varnish  26995  0.0  0.0 118992  7424 ?        Ss   Jan07   0:02 /usr/sbin/varnishd -a :6081 -T 127.0.0.1:6082 -P /run/varnishd.pid -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,16G
vcache   27009 30.7 58.6 29486828 18844444 ?   Sl   Jan07 425:38 /usr/sbin/varnishd -a :6081 -T 127.0.0.1:6082 -P /run/varnishd.pid -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,16G

bitfoo1 avatar Jan 08 '19 14:01 bitfoo1

and these as well please

# ps -C varnishd

# pc -C varnishd -o rss | grep -v RSS

richardforth avatar Jan 08 '19 14:01 richardforth

Oh. Sorry did't see that.

# ps -C varnishd
  PID TTY          TIME CMD
26995 ?        00:00:02 varnishd

# ps -C varnishd -o rss | grep -v RSS
 7424

# ps auxfwww | grep varnishd
root     14102  0.0  0.0  13096   908 pts/0    S+   15:09   0:00                      \_ grep --color=auto varnishd
varnish  26995  0.0  0.0 118992  7424 ?        Ss   Jan07   0:02 /usr/sbin/varnishd -a :6081 -T 127.0.0.1:6082 -P /run/varnishd.pid -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,16G
vcache   27009 30.7 57.7 29486828 18552600 ?   Sl   Jan07 436:03  \_ /usr/sbin/varnishd -a :6081 -T 127.0.0.1:6082 -P /run/varnishd.pid -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,16G

bitfoo1 avatar Jan 08 '19 15:01 bitfoo1

Interesting, I wonder if its only picking up the root one by default, not ones owned by other users. the ps output only appears to pick up the 7424 one, which is odd.

Can you confirm how you set it to run as vcache, and i'll do some testing this end.

If eh name vcache is arbitrary then i may not be able to do much but you are right, its shoudl be picking up that second process as well, and its not. Which is a cause of concern.

One thing you do have to bear in mind is that apache2buddy pretty much only works with stock installations, anything custom is likely to break its functionality. I usually recommend that peopl fork my work and createa custom version for their own uses, but this one is interesting, and I'd like to solve it.

richardforth avatar Jan 08 '19 15:01 richardforth

As you can see in the varnish changelog for versions > 4.1 it sets it automatically. https://varnish-cache.org/docs/4.1/whats-new/changes.html

bitfoo1 avatar Jan 08 '19 15:01 bitfoo1

Ah cool

Fair play, I may need to tweak some stuff for varnish 4, I will have a play and let you know. Thanks for raising this issue!

Kind Regards Richard

richardforth avatar Jan 08 '19 15:01 richardforth

Hey @richardforth any progress on that?

bitfoo1 avatar Feb 04 '19 19:02 bitfoo1

Hi

Its still on my to do list. Sorry I have been slammed with work. But I will look into it when I get some free time.

Apache2buddy isn't funded so I get to it when I can.

I will certainly look into this for you.

Kind regards Richard

On Mon, 4 Feb 2019, 19:40 Daniel Thielking <[email protected] wrote:

Hey @richardforth https://github.com/richardforth any progress on that?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/richardforth/apache2buddy/issues/283#issuecomment-460383604, or mute the thread https://github.com/notifications/unsubscribe-auth/AFpUV5O0oHrPiKtN5p7tVyoiTrLaXxZEks5vKIyWgaJpZM4Z0YE1 .

richardforth avatar Feb 04 '19 20:02 richardforth

Hi, no problem, I just wanted to ask. If I can provide more information, just let me know.

Kind regards Daniel

bitfoo1 avatar Feb 05 '19 09:02 bitfoo1

Hi,

What OS are you running? I just tried to replicate this on CentOS7 but failed. not sure if the vcache thing is an ubuntuism. They like to do things differently it seems.

Kind Regards Richard

256 stock malloc ona 1gb test server

[ -- ] Varnish Detected => Using 176.93 MB of memory.

[root@server-01 ~]# ps auxfwww | grep varnish
root      5644  0.0  0.0 112708   936 pts/0    S+   15:41   0:00          \_ grep --color=auto varnish
varnish   5161  0.1  8.7 122856 88076 ?        SLs  15:40   0:00 /usr/sbin/varnishd -P /var/run/varnish.pid -f /etc/varnish/default.vcl -a :6081 -T 127.0.0.1:6082 -S /etc/varnish/secret -s malloc,256M
varnish   5162  0.2  9.2 270672 93092 ?        Sl   15:40   0:00  \_ /usr/sbin/varnishd -P /var/run/varnish.pid -f /etc/varnish/default.vcl -a :6081 -T 127.0.0.1:6082 -S /etc/varnish/secret -s malloc,256M
[root@server-01 ~]# ps auxfwww | grep vcache
root      5660  0.0  0.0 112708   936 pts/0    S+   15:42   0:00          \_ grep --color=auto vcache

richardforth avatar Feb 05 '19 15:02 richardforth

Yes you are totally right. I'm using Ubuntu 14.04 and 18.04 with Varnish 5.1.3.

bitfoo1 avatar Feb 06 '19 09:02 bitfoo1

Ok cool. I'll try and run some more tests later on when I get a chance - once I can replicate it in my environment I can start coding for it to pick up the vcache. thanks for getting back to me :)

richardforth avatar Feb 06 '19 09:02 richardforth

Sure! Great thanks to you for helping me out.

bitfoo1 avatar Feb 06 '19 09:02 bitfoo1

Just to let you know I got a cloudserver with 18.04 and varnish 5.2.1-1 - hopefully were cooking on gas now. i will let you know how it goes.

richardforth avatar Feb 09 '19 11:02 richardforth

Great! Let me know when you need support. After you got something I can test it on Ubuntu 14.04.

bitfoo1 avatar Feb 09 '19 11:02 bitfoo1

good news is out-of -the box like straight after apt-get install I can see the issue exactly as described:

root@ubu1804:~# ps auxfwww | grep varn
root     10010  0.0  0.1  14852  1096 pts/1    S+   13:33   0:00  |       \_ grep --color=auto varn
vcache    6447  0.0  0.4  36996  4232 ?        SLs  11:25   0:00 /usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
vcache    6543  0.0  0.6 260980  6208 ?        SLl  11:25   0:01  \_ /usr/sbin/varnishd -j unix,user=vcache -F -a :6081 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
varnish+  6762  0.3  0.0  99136   168 ?        Ss   11:25   0:24 /usr/bin/varnishncsa -a -w /var/log/varnish/varnishncsa.log -D -P /run/varnishncsa/varnishncsa.pid
root@ubu1804:~#

Now I just have to work out how exactly I am going to code around this....

*thinkingface

richardforth avatar Feb 09 '19 13:02 richardforth

	# Detect Varnish
	our $varnish_detected = 0;
	$varnish_detected = `ps -C varnishd -o rss | grep -v RSS`;
	if ( $varnish_detected ) { 
		if ($VERBOSE) { print "VERBOSE: Varnish Detected\n" }
		our $servicefound_flag = 1;
		if ( ! $NOINFO ) { show_info_box(); print "${CYAN}Varnish${ENDC} Detected => " }
		# Get varnish Memory Usage
		our $varnish_memory_usage_mbytes = get_service_memory_usage_mbytes("varnishd");
		if ( ! $NOINFO ) { print "Using ${CYAN}$varnish_memory_usage_mbytes MB${ENDC} of memory.\n" }
	} else {
		if ($VERBOSE) { print "VERBOSE: Varnish NOT Detected\n" }
		our $varnish_memory_usage_mbytes = 0;
	}

Heres what we are looking at in term of the current code. I'll be staring at this for a while now until something hits me. If you come up with any ideas I am open. but we need to add extra logic in to search for vcache and take that into account as well....and its supposed to be simple - after all this isnt varnishbuddy....KISS - keep it simple stupid.

What about an "egrep" so we capture either both or one depending on whats found?

or

are there additional switched we can use to alter this line:

$varnish_detected = `ps -C varnishd -o rss | grep -v RSS`;

as i think just -C only looks for root-owned processes......

would

$varnish_detected = `ps -aC varnishd -o rss | grep -v RSS`;

work?

hmmm

*puffs on imaginary cigar and looks out of his imaginary window in deep thought........

richardforth avatar Feb 09 '19 13:02 richardforth