View Full Version : xcache configuration help needed
hornstar6969
Wed 5th Dec '07, 7:10pm
I have had xcache installed for quite a while, but never even thought about configuring it right until yesterday when the server load increased heaps and become really laggy. So here I am :)
I played around with the config and installed xcache admin and the server load has improved, but i'm sure it can be improved more as I am not to sure about the hits and misses part. I have had it running for over 12 hours on this set up currently.
My server specs: http://www.vbulletin.com/forum/showthread.php?t=244971
and I have attached a screen shot of what is shown in the xcache admin panel.
Any help is much appreciate. Thanks.
eva2000
Thu 6th Dec '07, 8:26pm
overallocation of memory there.. var size can be dropped to 2M if you just using the xcache datastore hack from vB.org and xcache size can be dropped to 128M
hornstar6969
Fri 7th Dec '07, 3:56am
I am using vbseo, and it now has a new xcache feature. Not sure if it is similiar to the vb.org hack you mentioned. But if not, should I install the vb.org hack?
proxxx
Fri 7th Dec '07, 5:01am
I am also using the vbseo's xcache, and would like to know if I should install the vb.org's datastore
TECK
Fri 7th Dec '07, 5:20am
Install memcached on the db server and use it's free memory (that sits there unused) to boost your server performance. If you only have one server (web and db installed on the same machine), enable query_cache, it is way faster. Use XCache to cache PHP compiled code, not the vB datastore.
And you should clean the XCache cache every 3 hours, so you avoid clugs on busy sites.
hornstar6969
Fri 7th Dec '07, 9:06pm
Install memcached on the db server and use it's free memory (that sits there unused) to boost your server performance. If you only have one server (web and db installed on the same machine), enable query_cache, it is way faster. Use XCache to cache PHP compiled code, not the vB datastore.
And you should clean the XCache cache every 3 hours, so you avoid clugs on busy sites.
That sounds like very good advice, but if it can be broken down a little more, it would really help here.
I am on just one dedicated server.
1. How do I enable query_cache?
I found this info:
Many times developers looking for ways to speed up query, in mysql we can enable query cache to speed up query performance. Whenever query cache is enable, it will cache the query in memory and boost query performance.
As we know, speed is always the most important element in developing a website especially for those high traffic database driven website. You can try to turn on query cache to speed up query.
To speed up query, enable the MySQL query cache, before that you need to set few variables in mysql configuration file (usually is my.cnf or my.ini)
- 1st, set query_cache_type to 1. (There are 3 possible settings: 0 (disable / off), 1 (enable / on) and 2 (on demand).query-cache-type = 1
- 2nd, set query_cache_size to your expected size. I’d prefer to set it at 20MB. query-cache-size = 20M
If you set your query-cache-type = 2 ( on demand ), you would wan to modify your sql query to support cache.SELECT SQL_CACHE field1, field2 FROM table1 WHERE field3 = ‘yes’
To check if your mysql server already enable query cache, simply run this query:-SHOW VARIABLES LIKE ‘%query_cache%’;
You will see this result:- +——————-+———+
| Variable_name | Value |
+——————-+———+
| have_query_cache | YES |
| query_cache_limit | 1048576 |
| query_cache_size | 20971520 |
| query_cache_type | ON |
+——————-+———+
4 rows in set (0.06 sec)
To check if your MySQL query cache is working, simply perform a sql query for 2 times and check the query cache variable like below:-SHOW STATUS LIKE ‘%qcache%’;
+————————-+———-+
| Variable_name | Value |
+————————-+———-+
| Qcache_queries_in_cache | 1 |
| Qcache_inserts | 3 |
| Qcache_hits | 0 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 2 |
| Qcache_free_memory | 20947592 |
| Qcache_free_blocks | 1 |
| Qcache_total_blocks | 4 |
+————————-+———-+
For the first time you execute your SQL query, the time it should take take be longer compare to the second time query. This is due to the MySQL query cache is working!
Just follow that for #1?
2. Maybe a stupid question, but not sure if XCache is caching php compiled code already, and if not, how do I get it to do this? and not sure if the vb datastore is being used, and if so, how will I disable this after.
3. How do you clean the XCache cache every 3 hours?
Thanks.
hornstar6969
Sat 8th Dec '07, 12:37am
Also, on top of the above post, this is my current settings, is that good or not?
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 128M
xcache.count = 2
xcache.slots = 2K
xcache.ttl = 3600
xcache.gc_interval = 300
xcache.var_size = 2M
xcache.var_count = 2
xcache.var_slots = 2K
xcache.var_ttl = 0
xcache.var_maxttl = 0
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
TECK
Sat 8th Dec '07, 5:09pm
1. You are using MySQL 5.0.x I'm sure, since we are not in the stone age anymore.
Read this tutorial I wrote:
http://www.yqed.com/technology/unix/enable-mysql-query-cache.html
2. By default, XCache is caching php compiled code. DO NOT cache the datastore with XCache.
3. You have a real dual core? Use this configuration settings:
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 64M
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 7200
xcache.gc_interval = 300
xcache.var_size = 64M
xcache.var_count = 2
xcache.var_slots = 8K
xcache.var_ttl = 7200
xcache.var_maxttl = 14400
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = Off
xcache.coveragedump_directory = ""
hornstar6969
Sun 9th Dec '07, 3:03am
1. You are using MySQL 5.0.x I'm sure, since we are not in the stone age anymore.
Read this tutorial I wrote:
http://www.yqed.com/technology/unix/enable-mysql-query-cache.html
2. By default, XCache is caching php compiled code. DO NOT cache the datastore with XCache.
3. You have a real dual core? Use this configuration settings:
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 64M
xcache.count = 2
xcache.slots = 8K
xcache.ttl = 7200
xcache.gc_interval = 300
xcache.var_size = 64M
xcache.var_count = 2
xcache.var_slots = 8K
xcache.var_ttl = 7200
xcache.var_maxttl = 14400
xcache.var_gc_interval = 300
xcache.test = Off
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.coredump_directory = ""
xcache.cacher = On
xcache.stat = On
xcache.optimizer = Off
[xcache.coverager]
xcache.coverager = Off
xcache.coveragedump_directory = ""
This is my server specs
cpu speed/type single or dual cpus): Intel Quad-Core Xeon E5320 / 1.86GHz - 8MB cache
how much memory installed: 4GB ram
hard drive type/configuration: 2 x 143GB SCSI 15k RPM drives - 3ware RAID1
linux distributor: Centos 4.3 (I think that is the version)
apache: apache 1.3.39
PHP version: php 5.2.3
MySQL version: mysql 5.0.27-standard
Do you still recommend the same settings?
and How do you clean the XCache cache every 3 hours?
TECK
Sun 9th Dec '07, 5:12pm
You have good hardware there, good choice. :)
If you can, try to change the disks for SAS, they are better then SCSI.
You also need to toss Crapache and install lighttpd instead, if you want your site to fly.
To see how many CPU's you have, do:
$ cat /proc/cpuinfo | grep -c processor
See what value returns and set the xcache.count and xcache.var_count to match it (SplittedCache setting).
The recommended value to use is count of your CPU + 1, but you can always try to tune it yourself like other settings. From my experience, I noticed that setting the count to the same value will increase the server load. I usually set it to (returned value / 2). In other words, if the result is 8, I set the values to 4.
The xcache.slots setting is also important to tweak. More slots means faster searching the cache but take more memory. 8K is a good value, but you have to experiment yourself.
The xcache.ttl and xcache.var_ttl settings reflect the Ttl (Time To Live) for the php entry (cached opcodes of a file). This is the setting you need to tweak, in order to avoid clogs. In my example I set it to 2 hours because it is a busy cache and I like to keep clean data. Set it to 10800 (60 * 60 * 3), for a 3 hours cleanup.
To see your CentOS version, do:
$ cat /etc/redhat-release
hornstar6969
Mon 10th Dec '07, 5:56am
Thanks for that useful information, however doing that command gave me this:
[root@server ~]# $ cat /proc/cpuinfo | grep -c processor
-bash: $: command not found
0
[root@server ~]#
Also I am using cpanel/whm I am not sure if I can use lighttpd, correct me if I am wrong tho.
I also think I am on SAS, I was originally going to get SCSI but then got SAS at the last minute, but never changed my specs in my notepad file.
Do you think upgrading from 4gig of ram to 8 gig of ram could be a good choice?
TECK
Mon 10th Dec '07, 11:18am
The $ means the command can be run by a regular users, you don't have to be root.
The # means only root can run this command. In other words, instead of:
[root@server ~]#
you will write:
#
People will know you have to run the command as root.
Following to this little Unix intro, tell me what is the processor count:
$ cat /proc/cpuinfo | grep -c processor
About your upgrade, it depends. You are the only person who knows your server stats.
If your box is busy, get a second/third server. :)
And I'm pretty sure many experienced server admins are totally against cPanel and other similar "gadgets".
Personally, I don't deal with any server that have it installed. :)
hornstar6969
Tue 11th Dec '07, 4:18am
Thanks,
My processor count is: 4
TECK
Wed 12th Dec '07, 4:13am
Set the xcache.count and xcache.var_count to 4.
hornstar6969
Fri 14th Dec '07, 4:17am
Set the xcache.count and xcache.var_count to 4.
Thanks, just wondering, is it httpd that I restart after editing the php.ini file or is it meant to be another service I restart?
Thanks.
Milez
Fri 14th Dec '07, 4:56am
Httpd dude. Great advise in this thread Teck.
How superior is Xcache compared to APC (which I currently use) ? XCache seems quite a bit more complicated to configure.
TECK
Fri 14th Dec '07, 9:38am
Thanks, just wondering, is it httpd that I restart after editing the php.ini file or is it meant to be another service I restart?
Thanks.
Yes, use Crapache if you want to have a higher server load and waist money on extra memory usage and resources that could be used way better for other software in your system.
lighttpd will blow Crapache by a long shot. You might want to read this link/thread (http://www.vbulletin.com/forum/showpost.php?p=1449953&postcount=8) why lighty is better. I remember when I moved a client to lighty... his server load dropped from 1.25 to 0.25. However, you need to know what you do, in order to obtain those results, they are not donable out of the box.
Httpd dude. Great advise in this thread Teck.
How superior is Xcache compared to APC (which I currently use) ? XCache seems quite a bit more complicated to configure.
I like XCache because it allows me to tweak it way better then APC.
The tweaking is very easy, all you need to do is read the Trac documentation to see what options does. Then, simply edit it for your needs.
the Sandman
Fri 14th Dec '07, 1:10pm
DO NOT cache the datastore with XCache.Why not? :confused:
TECK
Fri 14th Dec '07, 11:12pm
Why not? :confused:
Because you want to keep the processes separated, so you improve performance.
PHP compiled code with XCache and MySQL data with memcached.
Let memcached take advantage of the unused memory on your db server, no need to put extra stress on your web server.
the Sandman
Fri 14th Dec '07, 11:53pm
Because you want to keep the processes separated, so you improve performance.
PHP compiled code with XCache and MySQL data with memcached.
Let memcached take advantage of the unused memory on your db server, no need to put extra stress on your web server.And in a one server setup?
stormblast-
Sat 15th Dec '07, 5:24am
Yes, use Crapache if you want to have a higher server load and waist money on extra memory usage and resources that could be used way better for other software in your system.
lighttpd will blow Crapache by a long shot. You might want to read this link/thread (http://www.vbulletin.com/forum/showpost.php?p=1449953&postcount=8) why lighty is better. I remember when I moved a client to lighty... his server load dropped from 1.25 to 0.25. However, you need to know what you do, in order to obtain those results, they are not donable out of the box.
The big drawback with Lighttpd is, that it's rewrite functionality is so different. I'm having trouble with vBSEO, Wordpress Mu, MediaWiki and all the stuff which relies on .htaccess and the Apache2 mod_rewrite module.. :/
TECK
Sat 15th Dec '07, 9:51pm
It is not a drawback, it is very easy. I actually helped a vBSEO customer to set it up.
For example if I want to password protect a directory, I enable mod_auth and set my info into lighty configuration file.
var.basedir = "/var/www/"
$HTTP["host"] == "www.example.com" {
var.servername = "example.com"
server.document-root = basedir + servername + "/forum/"
auth.backend = "htpasswd"
auth.backend.htpasswd.userfile = basedir + servername + "/htpasswd"
auth.require = (
"/admincp" => (
"method" => "basic",
"realm" => "vBulletin Admin CP",
"require" => "valid-user"
)
)
}
mod_magnet and mod_auth are made especially to replace the .htaccess files.
You will not find many tutorials on the Internet because people are getting mad at you for asking those questions. Why? It is way to well explained on the lighty trac site. Just go and read all the documentation, instead of waiting for others to write a tutorial so you can just copy/paste. I go balistic when I see that the lighty's full potential is used only at 1% because nobody takes the time to read it's well written documentation.
I bet not many people know that you can use includes or variables (like in the example listed above) in your lighty configuration. That is because nobody wrote a tutorial where you can copy/paste like a robot, without using logic.
Read the documentation (http://trac.lighttpd.net/trac/wiki/Docs), the developers spent a lot of time on it to make your life easy.
Sorry, it might sound harsh, but I get mad when I read those posts... no disrespect intended to anyone.
TECK
Sat 15th Dec '07, 9:55pm
And in a one server setup?
Read post #5. :)
SemperFideles
Fri 4th Jan '08, 12:16pm
Install memcached on the db server and use it's free memory (that sits there unused) to boost your server performance. If you only have one server (web and db installed on the same machine), enable query_cache, it is way faster. Use XCache to cache PHP compiled code, not the vB datastore.
And you should clean the XCache cache every 3 hours, so you avoid clugs on busy sites.
I followed the instructions to enable mySQL datastore using your instructions. XCache had been installed successfully previous to doing this in addition to the vb.org template cache and xcache enabled for vbseo.
This was my XCache settings:
[xcache]
xcache.shm_scheme = "mmap"
xcache.size = 256M
xcache.count = 2
xcache.slots = 2K
xcache.readonly_protection = Off
xcache.mmap_path = "/dev/zero"
xcache.stat = On
xcache.cacher = On
xcache.ttl = 3600
xcache.gc_interval = 300
; same as aboves but for variable cache
xcache.var_size = 8M
xcache.var_count = 2
xcache.var_slots = 2K
; default ttl
xcache.var_ttl = 3600
xcache.var_maxttl = 7200
xcache.var_gc_interval = 300
But when I had the combination of the mySQL Query Cache + XCache above + Template Cache + vBSEO Xcache enabled - some users weren't able to access PM while others could not view some threads.
Do you think the problem was my XCache config or was it enabling the template cache or enabling the Xcache for vbseo?
TECK
Fri 4th Jan '08, 2:54pm
Curious, when you say "enabling the template cache"... what do you mean by that?
vBulletin does not have a cache system for templates. Be aware that previous hacks released at vb.org were very incomplete, related to caching. They actually created more bugs then cache the templates properly.
You should also disable all your products, for testing purposes. In this way, you identify easier the source of the problem. If your users don't have any issues, enable each product until you know who is the culprit that breaks your software.
I recently abandoned lighttpd, in favor of Nginx (http://www.vbulletin.com/forum/showthread.php?t=253741).
SemperFideles
Fri 4th Jan '08, 6:10pm
Curious, when you say "enabling the template cache"... what do you mean by that?
vBulletin does not have a cache system for templates. Be aware that previous hacks released at vb.org were very incomplete, related to caching. They actually created more bugs then cache the templates properly.
I meant the vb.org version: http://www.vbulletin.org/forum/showthread.php?t=139151
You should also disable all your products, for testing purposes. In this way, you identify easier the source of the problem. If your users don't have any issues, enable each product until you know who is the culprit that breaks your software.
I recently abandoned lighttpd, in favor of Nginx (http://www.vbulletin.com/forum/showthread.php?t=253741).
I'd love to do the same but am simply not skilled enough to work through all the potential problems I'll encounter.
Thanks for your help and your blog. It is very useful.
vBulletin® v3.8.0 Beta 4, Copyright ©2000-2008, Jelsoft Enterprises Ltd.