Google Code Prettify

2012年7月2日 星期一

Apache http Server 2.4 效能解放


Apache 2.4 宣佈已經可以跟 Nginx比拼了
但很多網路文章卻測不出這個效能

一開始我也沒辦法解放它的效能
經過數次的安裝移除的循環
發現一個重要的參數: --with-mpm
必須安裝為 event Multi-Processing Module
這就是解放效能的所在囉

什麼是 event module, 其實就是 linux EPoll,Nginx 也是應用這個模式


Apache 2.4 安裝步驟

#安裝 APR
tar -zxvf apr-1.4.6.tar.gz
cd apr-1.4.6
./configure --prefix=/usr/local/apache-apr --enable-nonportable-atomics=yes
make
sudo make install

#安裝 APR-UTIL apr-util
tar -zxvf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1
./configure --prefix=/usr/local/apache-apr --with-apr=/usr/local/apache-apr
make
sudo make install

unzip -o pcre-8.30.zip
cd pcre-8.30
./configure --prefix=/usr/local/pcre --enable-utf --enable-unicode-properties
make
sudo make install

#安裝 apache server
1. tar -zxvf httpd-2.4.2.tar.gz

2. cd httpd-2.4.2

3. ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apache-apr --with-apr-util=/usr/local/apache-apr --with-pcre=/usr/local/pcre --with-mpm=event \
--enable-nonportable-atomics=yes \
--enable-mods-shared=all \
--enable-expires=shared \
--enable-headers=shared \
--enable-reqtimeout=shared \
--enable-ssl=shared \
--enable-rewrite=shared \
--enable-speling=shared \
--enable-proxy=shared \
--enable-proxy-connect=shared \
--enable-proxy-ajp=shared \
--enable-proxy-balancer=shared \
--enable-proxy-express=shared \
--enable-info=shared \
--enable-heartbeat=shared \
--enable-heartmonitor=shared \
--enable-ratelimit=shared \
--enable-remoteip=shared \
--enable-allowmethods=shared

4. make

5. sudo make install

6.Check Apache MPM 是 event
/usr/local/apache2.4/bin/httpd -l
/usr/local/apache2.4/bin/httpd -V | grep MPM

#效能調整
#修改 httpd-mpm.conf 下的mpm_event_module

    StartServers             2
    MinSpareThreads         25
    MaxSpareThreads         75
    ThreadsPerChild         25
    MaxRequestWorkers      150
    MaxConnectionsPerChild   0

利用 Ghostscript 重新產生PDF


Ghostscript
http://pages.cs.wisc.edu/~ghost/


完整參數
http://www.ghostscript.com/doc/current/Use.htm


範例指令

 轉換為600dpi
 gswin32c -dNOPAUSE -dBATCH -q -r600 -sDEVICE=pdfwrite -sOutputFile=out.pdf input.pdf

指定頁數
gswin32c -dNOPAUSE -dBATCH -q -r600 -sDEVICE=pdfwrite -dFirstPage=22 -dLastPage=36 -sOutputFile=out.pdf input.pdf

pdfwrite Additional Options

PDF optimization level selection options
 -dPDFSETTINGS=/screen   (screen-view-only quality, 72 dpi images)
 -dPDFSETTINGS=/ebook    (low quality, 150 dpi images)
 -dPDFSETTINGS=/printer  (high quality, 300 dpi images)
 -dPDFSETTINGS=/prepress (high quality, color preserving, 300 dpi imgs)
 -dPDFSETTINGS=/default  (almost identical to /screen)


Paper size selection options
 -sPAPERSIZE=letter
 -sPAPERSIZE=a4
 -dDEVICEWIDTHPOINTS=w -dDEVICEHEIGHTPOINTS=h (point=1/72 of an inch)
 -dFIXEDMEDIA (force paper size over the PostScript defined size)

Other options
 -dEmbedAllFonts=true
 -dSubsetFonts=false
 -dFirstPage=pagenumber
 -dLastPage=pagenumber
 -dAutoRotatePages=/PageByPage
 -dAutoRotatePages=/All
 -dAutoRotatePages=/None
 -r1200 (resolution for pattern fills and fonts converted to bitmaps)
 -sPDFPassword=password
 -dConvertCMYKImagesToRGB=true
 -dCompatibilityLevel=1.5

更多參數請參考 Ps2pdf.htm