顯示具有 SeverTuning 標籤的文章。 顯示所有文章
顯示具有 SeverTuning 標籤的文章。 顯示所有文章

2010年7月19日 星期一

Server Spec Suggestion

1 Apache server can be smaller.
1.1 RAM: Even 1GB RAM will work.
1.2 Disk: if you have tons of pictures, I would suggest you can get smaller disks and more disk quantity. For example, 36GB X 4. With RAID1, total usable size would be 36G X 2. I think that’s enough for Apache server.
1.2.1 Disk1: OS and Apache server
1.2.2 Disk2: all data
1.3 CPU: Single CPU will work
2 DB server should be bigger
2.1 RAM: 2-4 GB, depends on how fast you want and MySQL’s limitation.
2.2 Disk: the more the better (RAID1 is MUST). My minimum suggestion:
2.2.1 Disk1: System
2.2.2 Disk2: Data & INDEX
2.2.3 Disk3: Transaction Log and Backup files
2.3 CPU: suggest 2 CPUs.

2010年5月26日 星期三

TCP Tuning for Busy Apache Webserver on CentOS5

Recently I was in a situation where a very busy webserver was not responding. Strangely, top showed plenty of CPU available. The server was essentially just sitting there. What do do?
Upon further investigation, it turned out that the network queue was saturated. So many incoming connections were being attempted that they were falling off the end. Some TCP tuning was in order. Fortunately the server was not memory-starved so allocating more memory to the network stack was not a problem. Here's what ended up in /etc/sysctl.conf and turned the server back into a faithful workhorse.
# Kernel tuning settings for CentOS5,
# busy webserver with lots of free memory.
# Big queue for the network device
net.core.netdev_max_backlog=30000
# Lots of local ports for connections
net.ipv4.tcp_max_tw_buckets=2000000
# Bump up send/receive buffer sizes
net.core.rmem_default=262141
net.core.wmem_default=262141
net.core.rmem_max=262141
net.core.wmem_max=262141
# Disable TCP selective acknowledgements
net.ipv4.tcp_sack=0
net.ipv4.tcp_dsack=0
# Decrease the amount of time we spend
# trying to maintain connections
net.ipv4.tcp_retries2=5
net.ipv4.tcp_fin_timeout=60
net.ipv4.tcp_keepalive_time=120
net.ipv4.tcp_keepalive_intvl=30
net.ipv4.tcp_keepalive_probes=3
# Increase the number of incoming connections
# that can queue up before dropping
net.core.somaxconn=256
# Increase option memory buffers
net.core.optmem_max=20480
There are plenty of other sysctl options to tune, but the above made the most difference.
And netstat -s is your friend.


摘自:http://www.sysarchitects.com/node/69

Linux Tuning Parameters

Using all the resources available to you?
Many default settings in Linux suck
Font server for X Windows is running as a daemon by default, but do you need it?
Check out these tunings that can give you lots of computing juice...
Kernel Network Disk I/O Others


Kernel
To successfully run enterprise applications, such as a database server, on your Linux distribution, you may be required to update some of the default kernel parameter settings. For example, the 2.4.x series kernel message queue parameter msgmni has a default value (for example, shared memory, or shmmax is only 33,554,432 bytes on Red Hat Linux by default) that allows only a limited number of simultaneous connections to a database. Here are some recommended values (by the IBM DB2 Support Web site) for database servers to run optimally:

- kernel.shmmax=268435456 for 32-bit
- kernel.shmmax=1073741824 for 64-bit
- kernel.msgmni=1024
- fs.file-max=8192
- kernel.sem="250 32000 32 1024"
Shared Memory

To view current settings, run command:
# more /proc/sys/kernel/shmmax
To set it to a new value for this running session, which takes effect immediately, run command:
# echo 268435456 > /proc/sys/kernel/shmmax
To set it to a new value permanently (so it survives reboots), modify the sysctl.conf file:
...
kernel.shmmax = 268435456
...
Semaphores

To view current settings, run command:
# more /proc/sys/kernel/sem
250 32000 32 1024
To set it to a new value for this running session, which takes effect immediately, run command:
# echo 500 512000 64 2048 > /proc/sys/kernel/sem
Parameters meaning:
SEMMSL - semaphores per ID
SEMMNS - (SEMMNI*SEMMSL) max semaphores in system
SEMOPM - max operations per semop call
SEMMNI - max semaphore identifiers
ulimits

To view current settings, run command:
# ulimit -a
To set it to a new value for this running session, which takes effect immediately, run command:
# ulimit -n 8800
# ulimit -n -1 // for unlimited; recommended if server isn't shared

Alternatively, if you want the changes to survive reboot, do the following:

- Exit all shell sessions for the user you want to change limits on.
- As root, edit the file /etc/security/limits.conf and add these two lines toward the end:
user1 soft nofile 16000
user1 hard nofile 20000
** the two lines above changes the max number of file handles - nofile - to new settings.
- Save the file.
- Login as the user1 again. The new changes will be in effect.

Message queues

To view current settings, run command:
# more /proc/sys/kernel/msgmni
# more /proc/sys/kernel/msgmax
To set it to a new value for this running session, which takes effect immediately, run command:
# echo 2048 > /proc/sys/kernel/msgmni
# echo 64000 > /proc/sys/kernel/msgmax

Network


Gigabit-based network interfaces have many performance-related parameters inside of their device driver such as CPU affinity. Also, the TCP protocol can be tuned to increase network throughput for connection-hungry applications.





Tune TCP

To view current TCP settings, run command:
# sysctl net.ipv4.tcp_keepalive_time
net.ipv4.tcp_keepalive_time = 7200 // 2 hours
where net.ipv4.tcp_keepalive_time is a TCP tuning parameter.
To set a TCP parameter to a value, run command:
# sysctl -w net.ipv4.tcp_keepalive_time=1800
A list of recommended TCP parameters, values, and their meanings:
Tuning Parameter Tuning Value Description of impact
------------------------------------------------------------------------------
net.ipv4.tcp_tw_reuse
net.ipv4.tcp_tw_recycle 1 Reuse sockets in the time-wait state
---
net.core.wmem_max 8388608 Increase the maximum write buffer queue size
---
net.core.rmem_max 8388608 Increase the maximum read buffer queue size
---
net.ipv4.tcp_rmem 4096 87380 8388608 Set the minimum, initial, and maximum sizes for the
read buffer. Note that this maximum should be less
than or equal to the value set in net.core.rmem_max.
---
net.ipv4.tcp_wmem 4096 87380 8388608 Set the minimum, initial, and maximum sizes for the
write buffer. Note that this maximum should be less
than or equal to the value set in net.core.wmem_max.
---
timeout_timewait echo 30 > /proc/sys/net/ipv4/tcp_fin_timeout Determines the time that must elapse before
TCP/IP can release a closed connection and reuse its resources.
This interval between closure and release is known as the TIME_WAIT
state or twice the maximum segment lifetime (2MSL) state.
During this time, reopening the connection to the client and
server cost less than establishing a new connection. By reducing the
value of this entry, TCP/IP can release closed connections faster, providing
more resources for new connections. Adjust this parameter if the running application
requires rapid release, the creation of new connections, and a low throughput
due to many connections sitting in the TIME_WAIT state.

Disk I/O


Choose the Right File System

Use 'ext3' file system in Linux.
- It is enhanced version of ext2
- With journaling capability - high level of data integrity (in event of unclean shutdown)
- It does not need to check disks on unclean shutdown and reboot (time consuming)
- Faster write - ext3 journaling optimizes hard drive head motion

# mke2fs -j -b 2048 -i 4096 /dev/sda
mke2fs 1.32 (09-Nov-2002)
/dev/sda is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=2048 (log=1)
Fragment size=2048 (log=1)
13107200 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
1600 block groups
16384 blocks per group, 16384 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,
2048000, 3981312, 5619712, 10240000, 11943936

Writing inode tables: done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Use 'noatime' File System Mount Option

Use 'noatime' option in the file system boot-up configuration file 'fstab'. Edit the fstab file under /etc. This option works the best if external storage is used, for example, SAN:

# more /etc/fstab
LABEL=/ / ext3 defaults 1 1
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
/dev/sdc2 swap swap defaults 0 0
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
/dev/sda /database ext3 defaults,noatime 1 2
/dev/sdb /logs ext3 defaults,noatime 1 2
/dev/sdc /multimediafiles ext3 defaults,noatime 1 2
Tune the Elevator Algorithm in Linux Kernel for Disk I/O

After choosing the file system, there are several kernel and mounting options that can affect it. One such kernel setting is the elevator algorithm. Tuning the elevator algorithm helps the system balance the need for low latency with the need to collect enough data to efficiently organize batches of read and write requests to the disk. The elevator algorithm can be adjusted with the following command:

# elvtune -r 1024 -w 2048 /dev/sda
/dev/sda elevator ID 2
read_latency: 1024
write_latency: 2048
max_bomb_segments: 6
The parameters are: read latency (-r), write latency (-w) and the device affected.
Red Hat recommends using a read latency half the size of the write latency (as shown).
As usual, to make this setting permanent, add the 'elvtune' command to the
/etc/rc.d/rc.local script.

Others
Disable Unnecessary Daemons (They Take up Memory and CPU)

There are daemons (background services) running on every server that are probably not needed. Disabling these daemons frees memory, decreases startup time, and decreases the number of processes that the CPU has to handle. A side benefit to this is increased security of the server because fewer daemons mean fewer exploitable processes.


Some example Linux daemons running by default (and should be disabled). Use command:
#/sbin/chkconfig --levels 2345 sendmail off
#/sbin/chkconfig sendmail off
Daemon
Description
apmd
Advanced power management daemon
autofs
Automatically mounts file systems on demand (i.e.: mounts a CD-ROM automatically)
cups
Common UNIX� Printing System
hpoj
HP OfficeJet support
isdn
ISDN modem support
netfs
Used in support of exporting NFS shares
nfslock
Used for file locking with NFS
pcmcia
PCMCIA support on a server
rhnsd
Red Hat Network update service for checking for updates and security errata
sendmail
Mail Transport Agent
xfs
Font server for X Windows
Shutdown GUI

Normally, there is no need for a GUI on a Linux server. All administration tasks can be achieved by the command line, redirecting the X display or through a Web browser interface. Modify the 'inittab' file to set boot level as 3:

To set the initial runlevel (3 instead of 5) of a machine at boot,
modify the /etc/inittab file as shown:



摘自:http://www.performancewiki.com/linux-tuning.html

2010年5月25日 星期二

CentOS 5: Eaccelerator Installation

eAccelerator is a free open-source PHP accelerator, optimizer, and dynamic content cache. It typically reduces server load and increases the speed of your PHP code by 1-10 times.
Through SSH.
yum install php-devel
yum groupinstall 'Development Tools'
Change directory.
cd /tmp
Get the file.
wget http://bart.eaccelerator.net/source/0.9.5.2/eaccelerator-0.9.5.2.tar.bz2
tar xvfj eaccelerator-0.9.5.2.tar.bz2
Change directory.
cd eaccelerator-0.9.5.2
Phpize.
phpize
./configure
Install it.
make
make install
Create the file /etc/php.d/eaccelerator.ini
vi /etc/php.d/eaccelerator.ini
Enter.
extension="eaccelerator.so"
eaccelerator.shm_size="0"
eaccelerator.cache_dir="/var/cache/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
Create /var/cache/eaccelerator ditrectory
mkdir -p /var/cache/eaccelerator
Change permission.
chmod 0777 /var/cache/eaccelerator
Restart Apache.
/etc/init.d/httpd restart

摘自:http://www.php.ph/2007/12/21/centos-5-eaccelerator-installation/

2010年5月19日 星期三

How to set permanent ulimit

First of all, it depends on whether you want this limit changed for
all users, all users of a group, or just one user, such as a database
server's userid. I'll give you an example for a single user.
I hope you can adapt these instructions if that's not the case.
Let's suppose that user "database" needs to be able to open up to
10240 files at once.

In /etc/security/limits.conf, add the following line:

database hard nofile 10240

In /home/database/.bash_profile add the following line:

ulimit -n 10240

Now shutdown and reboot. Now, whenever "database" logs in, his
file limit will be 10240. This assumes that the login shell for
database is bash. Of course, if a daemon needs these
privileges, this won't work, since there is no interactive
login shell. You may need to modify the daemon's start-up script
in this case to add the ulimit command.

If you want the limit to apply to all users, edit /etc/profile
instead of ~/.bash_profile. And in /etc/security/limits.conf,
substitute an asterisk (*) for the userid "database". Again,
this assumes an interactive login shell of bash. Daemons, since they don't
have an interactive login shell, won't execute that ulimit
command. You'll have to find a place to put it. The startup
script in /etc/init.d might be a good place. But watch for
upgrades to the startup script which remove the modification.
If someone else has a better idea for how to implement this,
let me know.

摘自:http://linux.derkeiler.com/Mailing-Lists/Debian/2010-01/msg01906.html

2010年5月18日 星期二

RHEL5.3 Tuning-Tweaking Linux network parameters

Allow the TCP stack to reuse sockets in the TIME-WAIT state:
# Allow reuse/recycling of TIME-WAIT sockets for new connections:
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1

Lowering the FIN Timeout value will shorten the TIME_WAIT state, freeing up resources for new connections. It is recommended when running applications that constantly create a lot of new connections – ie. a web server. The default is 60, and Sun recommends a value in the 15-30 range.
# Lower FIN timeout (default: 60):
net.ipv4.tcp_fin_timeout = 15

Tweak the TCP KeepAlive values:
# Wait time between isAlive interval probes (default: 75, recommended: 15-30):
net.ipv4.tcp_keepalive_intvl = 15
# Number of probes before timing out (default: 9, recommended: 5):
net.ipv4.tcp_keepalive_probes = 5

The default maximum for send/receive windows is 128Kb and it’s recommended to boost this to 8Mb:
# Maximum TCP Send Window:
net.core.wmem_max = 8388608
# Maximum TCP Receive Window:
net.core.rmem_max = 8388608

Also tweak the IPv4 rcv/snd buffers to use a maximum of 8Mb:
# Memory reserved for TCP rcv buffers (default: 4Kb 85Kb 4Mb):
net.ipv4.tcp_rmem = 4096 87380 8388608
# Memory reserved for TCP snd buffers (default: 4Kb 16Kb 4Mb):
net.ipv4.tcp_wmem = 4096 87380 8388608

If you’re using a lot of connections, you should make more local ports available. Default range gives a total of 28232 ports available. Increasing this range to 4096-65535 will give you 61439 local ports:
# Available local port range (default: 32768 61000):
net.ipv4.ip_local_port_range = 4096 65536

摘自:http://blog.spind.net/2008/11/28/tweaking-linux-network-parameters/

2010年1月27日 星期三

PHP minify

Combines, minifies, and caches JavaScript and CSS files on demand to speed up page loads.

Minify is a PHP5 app that helps you follow several of Yahoo!'s Rules for High Performance Web Sites.

It combines multiple CSS or Javascript files, removes unnecessary whitespace and comments, and serves them with gzip encoding and optimal client-side cache headers.

官網:http://code.google.com/p/minify/

Google的YSlow——Page Speed

先来看界面吧

和YSlow一样,“Page Speed”也是一个基于firebug附加组件的FireFox插件。虽然听起来有点拗口,但是意思很容易理解:如果你想用“Page Speed”,那么你就要安装firbug,而firebug是FireFox的一个附加组件,所以你也必须按照FireFox浏览器。同时另外一个意思是:IE!NO!Sorry!

“Page Speed”有两个面板,分别是“Page Speed”面板和“Page Speed Activity”面板。

“Page Speed”面板

Page Speed附加组件的Page Speed面板
和YSlow使用Yahoo的14条标准来衡量网页的综合速度一样,Page Speed通过Google指定的20条标准来衡量网页的综合速度。而Page Speed面板就是用来展现你的网页在Google20条标准上的得分。“Page Speed”通过分析你的网页加载、呈现速度,用20条标准来衡量,最终告知你的网页速度如何、哪种标准得分多少、问题所在、如何改进等信息。

“Page Speed Activity”面板

Page Speed附加组件的Page Speed Activity”面板
“Page Speed Activity”面板用于展现你的网页加载各种元素的所用时间,这样,你就可以更明确的知道到底是谁在浪费、占用大量的时间,从而更有针对性的进行改进。不同的阶段占用的时间,用不同的色块进行表示,恩,真是贴心的设计。

“Page Speed”的20条衡量标准

如果你对YSlow比较熟悉的话,那么一定会知道YSlow用于衡量网页速度的14条标准,而“Page Speed”有20条衡量标准,那么他们之间的到底有什么不同呢?Google又会给我们带来什么新的观点呢?

补充一下:如果你对YSlow的14条衡量标准不熟悉的话,您可以阅读一下,我以前写的两篇文章,分别是《如何提高网页的效率(上篇)——提高网页效率的14条准则》和《如何提高网页的效率(下篇)——Use YSlow to know why your web Slow》,文章较为详细的介绍了YSlow这个工具的使用,以及YSlow的14条衡量标准。这两篇文章同时也被收录到了《博客园精华集-web标准之道》一书当中。

继续补充:如果你想非常详细的了解YSlow的14条衡量标准的超详细讲解,那么你可以购买一本书,书的名字叫做:《高性能网站建设指南》,书的封面是一条经常出现在《人与兽》一类电影中的那种狗狗。


高性能网站建设指南
OK,不扯那么多了,让我们回到正题:“Page Speed”的20条衡量标准到底是什么呢?

Put CSS in the document head
将你的CSS样式表文件放在整个页面的头部。没有什么难理解的。css先下载下来,就能更快的渲染网页效果。从而让人们感觉网页速度很快。

更多关于"Put CSS in the document head"的更多详细解释,请看官方文档。

Use efficient CSS selectors
使用效率更高的CSS选择符。举个很简单的例子:尽量不要使用*号选择符:
*{padding:0;margin:0}
像这样的得分会很低,正确的办法应该是只对你想设置的标签元素进行设置,例如:
html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, font, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td {
margin: 0;
padding: 0;
}
如果你对本条有更多的兴趣,可以去看Use efficient CSS selectors官方文档的详细解释。

Leverage proxy caching
代理缓存。这个名词听起来好像很屌的样子,以至于我也是查了资料才知道:所谓proxy cacheing,就是一种公共缓存,用于静态资源,允许浏览器从最近的代理服务器上,而不是从远程的原始服务器,下载这些静态资源。这些代理服务器,通常而言就是有ISP,接入服务商所提供的。

这样的代理服务器缓存可以让通过同一ISP接入服务的用户共享这些静态资源,而节省原始服务器的带宽,以及下载速度也会大大提高,特别是对于局域网的用户有特别的好处。

关于“Leverage proxy caching”的文档资料,请看官方文档的详细解释。

Minify JavaScript
最小化JavaScript脚本。这个貌似没有什么好说的,压缩一下你的JavaScript脚本吧。

关于“Minify JavaScript”的更多文档资料,请看官方文档的详细解释吧。

Optimize images
优化图片,其实最经常使用的就是css script了,也有翻译为“css精灵”的,虽然翻译的很美好,但是其实很简单,就是将多个图形,放在张图片文件中。这样,可以有效的减少http请求的数量。

如果你对“Optimize images”有更多的兴趣,可以看这个。一个css cript的示例: 《【CSS翻转门】技术实例讲解(附源码下载)》。

Minimize cookie size
最小化你的cookie。cookie的确是个好东西,他可以让你在用户的客户端保存一些东西,但是,千万不要什么都往用户口袋里面塞。原因很简单,cookie大小有限,有最大限制,而且cookie过大会减慢网页呈现的速度。另外为了安全性考虑,也不要把所有的什么破铜烂铁都塞到cookie里面。

关于“Minimize cookie size”的更多文档资料:看这里。

Enable gzip compression
使用gzip压缩。详细这个大家应该已经比较熟悉了。说白了就是服务器向浏览器发的是经过压缩的页面,这样传输的字节就会大大减少,速度自然也就快了。


这幅图说明了gzip技术的工作原理
欲了解更多的“Enable gzip compression”资料,请看官方文档。

Combine external JavaScript
合并外部的JavaScript文件。道理很简单,依然是为了少读取.js文件,从而有效的减少http请求数量。


合并外部的JavaScript文件可以有效的减少http请求数量
更多的关于“Combine external JavaScript”的文档,可以看这个。

Minimize DNS lookups
最小化DNS查询。详情请看这个:Minimize DNS lookups规则详情。

Optimize the order of styles and scripts
优化样式表和脚本的顺序。如果你要是看过老赵的《挣脱浏览器的束缚》系列的话(本系列也已经收录到《博客园精华集-web标准之道》一书中)。就知道IE浏览器对同一个域名下的文件,同时只能下载2个文件。所以,到底先让哪些样式表先下载下来,让哪些脚本先下载下来,这个顺序就非常重要了。所以,如果有可能,请重视一下样式表和脚本的顺序吧。推荐的做法是:将css放在js文件上面,让css文件先被加载,这样就可以先让网页渲染出来,从而加快浏览者的感知速度。


IE浏览器对同一个域名下的文件,同时只能下载2个文件
关于“Optimize the order of styles and scripts”更多详情,请看这个。

Serve resources from a consistent URL
相同的资源,使用相同的url地址。道理很好理解,如果是相同的一张图片,就不要东方一下,西方一下,然后引用的时候使用不同的url地址。为什么要这样做,道理也很简单,因为——缓存!

更多“Serve resources from a consistent URL”详情,请看这里

Avoid CSS expressions
避免CSS表达式。这个我在《如何提高网页的效率(上篇)——提高网页效率的14条准则》一文中也有讲到。现在需要补充的是:IE8已经不再支持css表达式功能。

关于“Avoid CSS expressions”,更多详情看这里。

Parallelize downloads across hostnames
通过不同的主机同时下载网页资源。这个的道理已经在“Optimize the order of styles and scripts”这一准则中讲述过。道理依然是老赵的《挣脱浏览器的束缚》提到的原因:IE浏览器对同一个域名下的文件,同时只能下载2个文件。

更多关于“Parallelize downloads across hostnames”的详情,可以看这个。

Combine external CSS
合并外部的css文件。这条和“Combine external JavaScript”准则的道理一样。还是为了减少http请求数量。

关于“Combine external CSS”的更多详情,可以看这个。

Specify image dimensions
明确的指明图片的高度和宽度。很久很久以前,long long ago。一个同学问我:“明确的指明图片的宽度和高度,是否能加快页面的渲染速度?”当时我的答案是:“这个应该没有关系吧!”。看来,当时的我是误人子弟了。明确的指出图片的高度和宽度,能够有效的加快浏览器在渲染图片周围布局和绘制呈现时的速度。

更多关于“Specify image dimensions”的详情,可以看这里。

Minimize redirects
尽量避免重定向。道理很简单,你从A地点到你的同事B先生家,到了那里,他的邻居告诉你,B先生已经搬家了,搬到了C地点,于是,你又跑到C地点,然后C地点有个人告诉你,B先生现在又搬家了,已经搬到了D地点。于是你又跑到了D地点,才找到了这个B同事。而这个装B的B同事,告诉你,你如果直接就来D地点,就不用那么麻烦了,而且速度也会更快一些。网页的跳转和重定向的道理是一样的。

关于“Minimize redirects”的详细文档,可以看这里。

Defer loading of JavaScript
延期加载JavaScript。这个听起来真是个高科技的东西呀。其实这玩意还真是非常的有效呀。不仅可以延期加载脚本,像一些大的图片、flash也都可以延期加载。其实实现原来也不是很难,就是先不加载一些比较大的东西,当页面加载完毕后,再加载那些东西。

关于“Defer loading of JavaScript”的更多详情,请看这里。

更多相关资料

关于“Page Speed”的更多相关阅读。重要的下载链接在这里:点击进入Page Speed下载页面,支持现在最新的FireFox3.5.2版本。

摘自:http://www.cnblogs.com/JustinYoung/archive/2009/08/10/Page-Speed-Google.html

2009年10月6日 星期二

非mmcache!Memcached的應用:多網站伺服器 PHP 共享 Session

請注意是 Memcached 不是 mmcache,很多人搞不清楚他們兩個的不同!多半玩過 PHP 的人大概都聽過 mmcache,它是一個預編譯緩衝的 PHP 加速程式,能夠提升 PHP 的執行效能。但很少人聽過 Memcached ,因為大多人乍看之下都以為它是mmcache,使得它沒什麼機會介紹自己。事實上,若您正打算架構一個真正高負載的大型網站系統,你需要了解的並不是 mmcache,而是 memcached。

Memcached 是什麼?顧名思義,他是由記憶體(Memory)和暫存(cache)所組合起來的常駐程式(Daemon),你也可以稱它為『暫存伺服器』。 Memcached 能提供一個暫存資料的服務,透過網路供其他電腦使用。Memcached 有什麼用途?最常見的應用就是在網站伺服器的叢集,它能讓許多的網站伺服器 Session 互相流通使用。如果你正在傷透腦筋煩惱這一點,恭喜你找到解決方法了!

想要在網站伺服器的叢集中,多網站伺服器 Session 互相流通使用,首先你必須將 Memcached 架起來當 Session 分享伺服器,這邊建議你使用大的記憶體,最好是能多大就有多大,因為 Memcached 並不會以硬碟當資料暫存,而是會完全跑在記憶體上,所以若記憶被用完了,Memcached 就會無法再存放更多資料。

接著,你必須修改 PHP 的 Session Save Handler,讓 PHP 懂得利用 Memcached Server 存放 PHP 的 Session 資料並能從 Memcached Server 取出 Session 的資料。PHP提供了 session_set_save_handler() 函式讓我們能輕易修改 Session Save Handler ,以下是我修改後的 PHP 程式碼,你必須在呼叫 session_start() 之前使用:




define("SHARED_SESS_TIME", 3600); // Timeout

// Session Class by Fred

class Shared_Session
{
function init()
{
ini_set("session.use_trans_sid", 0);
ini_set("session.gc_maxlifetime", SHARED_SESS_TIME);
ini_set("session.use_cookies", 1);
ini_set("session.cookie_path", "/");
ini_set("session.cookie_domain", ".yourdomain.com.tw");

session_module_name("user");
session_set_save_handler(
array("Shared_Session", "open"),
array("Shared_Session", "close"),
array("Shared_Session", "read"),
array("Shared_Session", "write"),
array("Shared_Session", "destroy"),
array("Shared_Session", "gc")
);
}

function open($save_path, $session_name) {
return true;
}

function close() {
return true;
}

function read($sesskey) {
global $memcache;

return $memcache->get($sesskey);
}

function write($sesskey, $data) {
global $memcache;

$memcache->set($sesskey, $data, SHARED_SESS_TIME);

return true;
}

function destroy($sesskey) {
global $memcache;

$memcache->delete($sesskey);
$memcache->flush_all();

return true;
}

function gc($maxlifetime = null) {
return true;
}
}

$GLOBALS["memcache"] = memcache();
$GLOBALS["memcache"]->add_server("192.168.1.1", 11211);
$GLOBALS["memcache"]->add_server("192.168.1.2", 11211);
Shared_Session::init();

?>


其中粗字體的部分,是要特別修改的地方:

3600 是 Session 的生命周期﹝以秒為單位﹞,這應該不用再做太多解釋。
yourdomain.com.tw 是你的網域名稱:想像一個情況若是 Loadbalance 在用戶第一次連線分配用戶到A伺服器,第二次連線分配給同一用戶到B伺服器,會導致 B 伺服器無法透過 cookies 取得 A 伺服器分配給用戶的 session_id,因為 cookies 無法跨網域存取,解決方法是必須修改 cookies 的網域設定,讓 www1.yourdomain.com.tw、www2.yourdomain.com.tw、www3.yourdomain.com.tw...等等,都可以共同存取同一個 cookies ,以取得同一個 session_id,故此時你必須設定成為『.yourdomain.com.tw』。
192.168.1.1 這是你的 Memcached Server 的 IP 位置,這裡值得提的是 add_server() 方法,你可以有多行設定許多 IP 做 Loadbalance 負載分配,前面也講到 Memcached 是純粹使用記憶體,若其中一台機器記憶體滿了,本方法可以從中找到另一台可用的機器使用。故你可以建立一個 Memcached 的叢集來處理 Session。

因為我偷懶, Memcached 的安裝方法就沒寫了,去求助 google 大神,它應該會告訴你更多詳細的安裝資料。其實 Memcached 除了可應用在 Session 共享上,也可以應用在資料庫的資料暫存緩充,降低SQL Server負擔以提升速度。Memcached多好用?就看你怎麼用了!

摘自:http://fred-zone.blogspot.com/2006/08/mmcachememcached-php-session.html

2009年8月25日 星期二

nmon performance: A free tool to analyze AIX and Linux performance

Usage notes: This nmon tool is NOT OFFICIALLY SUPPORTED. No warrantee is given or implied, and you cannot obtain help with it from IBM. If you have a question on nmon, please go on the Performance Tools Forum site (see Resources) so that others can find and benefit from the answers. To protect your email address from junk mail, you need to create a USER ID first (takes 20 seconds at most).
The nmon tool runs on:
AIX® 4.1.5, 4.2.0 , 4.3.2, and 4.3.3 (nmon Version 9a: This version is functionally established and will not be developed further.)
AIX 5.1, 5.2, and 5.3 (nmon Version 10: This version now supports AIX 5.3 and POWER5™ processor-based machines, with SMT and shared CPU micro-partitions.)
Linux® SUSE SLES 9, Red Hat EL 3 and 4, Debian on pSeries® p5, and OpenPower™
Linux SUSE, Red Hat, and many recent distributions on x86 (Intel and AMD in 32-bit mode)
Linux SUSE and Red Hat on zSeries® or mainframe
The nmon tool is updated roughly every six months, or when new operating system releases are available. To place your name on the e-mail list for updates, contact Nigel Griffiths.
Use this tool together with nmon analyser (see Resources), which loads the nmon output file and automatically creates dozens of graphs.
Introduction
The nmon tool is designed for AIX and Linux performance specialists to use for monitoring and analyzing performance data, including:
CPU utilization
Memory use
Kernel statistics and run queue information
Disks I/O rates, transfers, and read/write ratios
Free space on file systems
Disk adapters
Network I/O rates, transfers, and read/write ratios
Paging space and paging rates
CPU and AIX specification
Top processors
IBM HTTP Web cache
User-defined disk groups
Machine details and resources
Asynchronous I/O -- AIX only
Workload Manager (WLM) -- AIX only
IBM TotalStorage® Enterprise Storage Server® (ESS) disks -- AIX only
Network File System (NFS)
Dynamic LPAR (DLPAR) changes -- only pSeries p5 and OpenPower for either AIX or Linux
Also included is a new tool to generate graphs from the nmon output and create .gif files that can be displayed on a Web site.
See the README file for more details.
Benefits of the tool
The nmon tool is helpful in presenting all the important performance tuning information on one screen and dynamically updating it. This efficient tool works on any dumb screen, telnet session, or even a dial-up line. In addition, it does not consume many CPU cycles, usually below two percent. On newer machines, CPU usage is well below one percent.
Data is displayed on the screen and updated once every two seconds, using a dumb screen. However, you can easily change this interval to a longer or shorter time period. If you stretch the window and display the data on X Windows, VNC, PuTTY, or similar, the nmon tool can output a great deal of information in one place.
The nmon tool can also capture the same data to a text file for later analysis and graphing for reports. The output is in a spreadsheet format (.csv).
Installing the tool
The tool is a stand-alone binary file (a different file for each AIX or Linux version) that you can install in five seconds, probably less if you type fast. Installation is simple:
Copy the nmonXXX.tar.Z file to the machine. If using FTP, remember to use binary mode.
Note: Version XXX replaces this example.
To uncompress the file, run uncompress nmonXX.tar.Z.
To extract the files, run tar xvf nmonXX.tar.
Read the README file.
To start the nmon tool, type nmon.
If you are the root user, you might need to type ./nmon.
Extra notes for using nmon 9 for AIX 4 only
You must be the root user or allow regular users to read the /dev/kmem file by typing the following command (as root):
chmod ugo+r /dev/kmem

If you want the disk statistics, then also run (as root):
chdev -l sys0 -a iostat=true

How to run the tool interactively
For running the tool interactively, read the front page of the file for a few hints. Then start the tool and use the one-key commands to see the data you want. For example, to get CPU, Memory, and Disk statistics, start nmon and type:
cmd

How to get help information while running interactively
Press the h key.
Additional help information
For additonal help information, try the following:
Type the nmon -? command for brief details.
Type the nmon -h command for full details.
Read the README file.
How to capture the data to a file for later analysis and graphing
Run nmon with the -f flag. See nmon -h for the details. But as an example, try to run nmon for an hour capturing data snapshots every 30 seconds by using: Â Â Â Â
nmon -f -s 30 -c 120
nmon -fT -s 30 -c 120

The second line also captures the top processes. Both of these create the output file in the current directory called: Â Â Â Â
_date_time.nmon

This file is in a comma-separated values (CVS) format and can be imported into a spreadsheet directly. If you are using Lotus® 1-2-3, the file needs to be sorted. (This is not required for the Excel version of the nmon analyser.) On AIX, follow this example: Â Â Â Â
sort -A mymachine_311201_1030.nmon > xxx.csv

Notes to save you time:
To load the nmon data capture file into a spreadsheet, check the spreadsheet documentation for loading CVS data files (.csv). Many spreadsheets accept this data as just one of the possible files to load or provide an import function to do this. Many spreadsheets have a fixed number of columns and rows. I suggest you collect a maximum of 300 snapshots to avoid hitting these issues.
When you are capturing data to a file, nmon disconnects from the shell to ensure that it continues running, even if you log out. This means that nmon can appear to crash, even though it's still running in the background. To see if the process is still running, type:
ps ?ef | grep nmon

Read the README file for more information about which version of nmon to run on your particular operating system.
nmon Version 10 for AIX 5 no longer uses /dev/kmem, but only public APIs. So, you don't have to chage the permissions on /dev/kmem, and there is no need to have 32- and 64-bit versions of nmon.
For AIX 5.1, 5.2, and 5.3, use nmon 10.
On AIX, don't report lslpp -Lcq bos.?p core dumps on AIX 5.1, about ML03 onwards. Also, WLM stats go missing after upgrading to AIX 5.2 ML5 to Nigel Griffiths, as these are AIX bugs. These are avoided by using nmon Version 10.
Don't use Microsoft® Windows® Telnet and use a larger window than 80 x 25 characters. Many developers use VNC and PuTTY to display nmon from a Windows machine -- why not do the same!
New features for nmon on AIX Version 10
New Features Description
Starting up There is also now a small shell script called "nmon" that starts the right nmon version. Place this script and nmon binaries in your $PATH and type: nmon. This version is now only compiled in 32-bit mode. So, it runs on 32- and 64-bit hardware. The idea is to make it easier to install and run.
N = NFS NFS is completely new for nmon 10.
p = Partitions This is for shared CPU partitions information -- the big p5/AIX5.3 feature.
C = CPU This is for machines with 32 plus CPUs -- up to 128 logical CPUs by demand.
c = CPU Details your physical CPU use -- if you are on a POWER5 with AIX 5.3 and in a shared CPU environment.
S = Subclass This is for WLM subclasses -- by request.
a = Disk adapters Gives you details of the disk adapter -- like their full type.
r = Resources This includes your CPU speed in MHz.
k = Kernel Gives some new fields.
L = Large pages Gives you large-page stats -- popular with high-performance guys.
D = Disk Gives you more information about your disks, disk type sizes, free, volume groups, adapter, and so forth.
n = Network Gives you information about your network adapters details, MTU, and errors.
m = Memory Gives you more details on where your memory is going, system (kernel) and processes, and active virtual memory.
-B This is a start-up option to remove the boxes.
Sample output for nmon 10 for AIX 5
Figure 1 below is a sample of the screen output. It shows the opening screen for AIX 5, with lots of useful information.

Figure 1. Sample output for nmon 10 for AIX 5

Figure 2 illustrates the details for CPU (this is a 4 CPU POWER5 machine with SMT switched on), memory use, kernel internal statistics, and disks statistics. Note: This logical partition (LPAR) is using six times its entitlement in half a CPU.

Figure 2. CPU details

Figure 3 shows the details of the network, NFS statistics, and journal filesystem use.

Figure 3. Network details

The details of the POWER5 shared processor micro-partitions statistics are shown in Figure 4 below.

Figure 4. LPAR details

Figure 5 illustrates the details of the Linux version of nmon, showing the CPU (this is a 2 CPU POWER5 machine with SMT switched on), LPAR statistics, memory use, network statistics, file system use, and disks statistics. Note: The physical CPU of this LPAR is only available with SUSE SLES9 Service Pack 1 and Red Hat EL 4 Update 1.

Figure 5. Linux version of nmon

Figure 6 shows the OS details of the machine, disk statistics (detailed mode), and the top processes.

Figure 6. Linux version of nmon continued

Obtaining the tool
The following download options are available:
You can download nmon and its tools from IBM Wiki at http://www-941.haw.ibm.com/collaboration/wiki/display/WikiPtype/nmon.
Check out the Performance Tools forum for nmon questions and ideas at http://www-03.ibm.com/systems/p/community/.

Resources
Learn
"nmon analyser -- A free tool to produce AIX performance reports" (developerWorks, April 2006): Produce a wealth of report-ready graphs from nmon output.

Check out the following IBM Redbooks for additional information on performance:
Understanding IBM pSeries Performance and Sizing, SG24-4810-01, Febraruary 2001
Database Performance on AIX in the DB2 UDB and Oracle Environments, SG24-5511, January 2003
AIX 5L Performance Tools Handbook,SG24-6039, August 2003

Check out other articles and tutorials written by Nigel Griffiths:
AIX and UNIX zone
Across IBM and developerWorks

"AIX 5 performance series: CPU monitoring and tuning": Browse through this article to get rid of your CPU bottlenecks and improve performance.

Search the AIX and UNIX library by topic:
System administration
Application development
Performance
Porting
Security
Tips
Tools and utilities
Java™ technology
Linux
Open source

AIX and UNIX: The AIX and UNIX developerWorks zone provides a wealth of information relating to all aspects of AIX systems administration and expanding your UNIX skills.

New to AIX and UNIX: Visit the New to AIX and UNIX page to learn more about AIX and UNIX.

AIX 5L™ Wiki: A collaborative environment for technical information related to AIX.

IBM Virtual Innovation Center for Hardware: This site is the primary source for all System p AIX development.

Safari bookstore: Visit this e-reference library to find specific technical resources.

developerWorks technical events and webcasts: Stay current with developerWorks technical events and webcasts.

Podcasts: Tune in and catch up with IBM technical experts.

Get products and technologies
IBM trial software: Build your next development project with software for download directly from developerWorks.

nmon: Download nmon and its tools.

Discuss
Participate in the developerWorks blogs and get involved in the developerWorks community.

Participate in the AIX and UNIX forums:
AIX 5L -- technical forum
AIX for Developers Forum
Cluster Systems Management
IBM Support Assistant
Performance Tools -- technical
Virtualization -- technical
More AIX and UNIX forums

nmon questions: Check out the Performance Tools forum for nmon questions and ideas.

About the author
Nigel Griffiths works in the IBM eServer® pSeries Technical Support Advanced Technology Group. He specialises in performance, sizing, tools, benchmarks, and Oracle RDBMS. The nmon tool was developed to support benchmarks and performance tuning for internal use, but by popular demand is given away to deserving friends. If you have a question on nmon, please go on the Performance Tools Forum site (see Resources) so that others can find and benefit from the answers. To protect your email address from junk mail, you need to create a USER ID first (takes 20 seconds at most).

摘自:http://www.ibm.com/developerworks/aix/library/au-analyze_aix/

2009年3月25日 星期三

Xen Server 5 試用感

我本身已用vmware 3.5 basic 版 上線使用一年多...
基本上一些 應用上問題 自己也解決不少...其實不算太有需求找尋其他虛擬化軟體

但是xenserver這次 功能太誘人了
免費版差不多是全部完整功能了

http://www.citrix.com/English/ps2/products/feature.asp?contentID=1686939
上面link 比較圖
1.Live motion !!! =vmotion 動態搬遷 VM
2.多實體機管理..
3.VM樣版..
4.其他功能請參考上述Link

額外購買的Essentials for XenServer (好像還未定價)
1.HA
2.自動控制管理(實體機資源吃高時 自動會搬動VM到別機)

License 下載點
http://downloadns.citrix.com.edgesuite.net/akdlm/3849/XenServer-free-license.xslic
2009 .3.25 會推出申請free licnese 機制
企業版到 2009. 4.2x

XenServer 5 本體下ISO載點
http://downloadns.citrix.com.edgesuite.net/akdlm/3401/XenServer-5.0.0-install-cd.iso

Linux VM樣版和工具
http://downloadns.citrix.com.edgesuite.net/akdlm/3402/XenServer-5.0.0-linux-cd.iso

Xencenter Windows 控制軟體
http://downloadns.citrix.com.edgesuite.net/akdlm/3403/XenServer-5.0.0-XenCenter.msi

AMD T105 無陣列卡 無痛安裝完成...為之前正式版Xenserver 企業版 授權 之前在T105 裝ESX 快裝到快吐血



Mount ISO 請參考

http://wiki.osslab.org.tw/index.php?title=%E5%AF%A6%E9%A9%97%E5%B0%88%E6%A1%88/Virtualization/Citrix_XenServer/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8_iso_%E5%AE%89%E8%A3%9D_VM

開始寫不好的...

1.mount iso 不支源中文檔名 iso
2.第一次裝雨林木風版快速XP 完全不行..(VMware ESX 到正常的很) 用他win pe內 ghost 才可 .....
3.系統空間 3GB ..ISO 這樣一定不夠放......還是我安裝法不對? XD (安裝時不像esx 可自由分割空間)
後來發現正解 XEN 5可用Mount NFS or CIFS(網芳) 的ISO 目錄. 通常請準備一個NAS VM 內放ISO跟一些常用軟體方便


[root@tpexen /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 3.8G 1.7G 2.0G 46% /
none 377M 0 377M 0% /dev/shm

[root@tpexen /]# mount
/dev/sda1 on / type ext3 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw)
none on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

[root@tpexen /]# uname -r
2.6.18-92.1.10.el5.xs5.0.0.394.644xen



XenServer VM內的 XP 效能.


實體效能對照


先說到此...Pools 試驗中

摘自:http://bbs.vmware.cn/thread-18763-1-1.html

2009年3月11日 星期三

Server Tuning

OS層
-Linux [xx] tuning
[xx]=kernel,nfs,nfsd,tcp,fs…
-Application compile >> RPM
[AP]=Apache,MySQL,PHP
-setup > 系統設定 [移除不必要之service]
-chkconfig --list | grep on

MySQL
-Sphinx-Free open-source SQL full-text search engine[http://www.sphinxsearch.com/]
-my.cnf tuning
-slow-query tuning
-MySQL移至RAM disk
-amoeba-負載均衡

Apache
-Apache Lucene-full-featured text search engine[http://lucene.apache.org/java/docs/]
-error_log處理
-改用nginx -HTTP server and mail proxy server
-dmessage處理
-squid cache

PHP
-error處理
-PHP catch exception機制

FileServer
-Storage + Cluster建置 [效能 + 容錯]
-Openfiler
-Opennas

MailServer
-Mail By Pass (避過FireWall)

Security
-Mod security(先寫log,沒問題後再開始運做)

測試軟體
-BadBoy software

其他建議
-HDD -> 1萬5千轉
-FireWall向上提一層
-/var mount至獨立HDD - 讓寫入log檔工作獨立運做

wibiya widget