国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
Plone性能 — 賽德軟件公司
Plone性能
Document Actions
如何優(yōu)化、提高 Plone 的性能

大家關(guān)注的Plone的主要問題之一是速度。不可否認(rèn),如果你第一次使用Plone,會感覺很慢。

總體來說,Plone不是世界上最快的系統(tǒng)。從一開始,Plone就是用Python構(gòu)建的,Python是一種不需要編譯的解釋語言。這種語言帶來了巨大的靈活性,但是無法追到最快速的應(yīng)用。

影響Plone速度的首要因素,Plone是一個(gè)非常復(fù)雜的系統(tǒng)。對于一個(gè)平常的HTML網(wǎng)站,可以做到從服務(wù)器載入只需要百分之一秒的時(shí)間(顯然在不考慮網(wǎng)絡(luò)條件下),Plone的主頁面是完全動(dòng)態(tài)地根據(jù)每個(gè)人的每次請求生成出來的。這導(dǎo)致可能需要5-6秒鐘的時(shí)間載入一個(gè)頁面。此外,Plone中包含的javascript和css頁面超過100kB,這樣會導(dǎo)致超過30秒的時(shí)間下載,這就會導(dǎo)致非常慢的感覺。顯然,如果你同一時(shí)間內(nèi)有更多的用戶訪問,plone基本上就變得不可用了。

這可不是一個(gè)好消息。

不過,情況并不是完全糟糕。Plone底層的Zope應(yīng)用程序從來就沒有說是一個(gè)web服務(wù)器。還好,我們可以使用Apache作為前端Web服務(wù)器,并通過反向代理的程序來處理所有來自Web的連接,

本文后面部分中,所有的比對數(shù)據(jù)都是在一臺1.8GHz, RAM 128MB的Intel Celeron服務(wù)器上測試的。該服務(wù)器運(yùn)行基本的Redhat 7.3版本。Python使用Python.org上預(yù)編譯好的RPM包,而Zope也是編譯好的。使用的Plone版本是Plone 2.0 rc3.

要設(shè)置一個(gè)反向代理非常容易。首先配置你的Zope不要運(yùn)行在80端口上。你可以修改Zope 2.5/2.6的啟動(dòng)腳本,或者編輯Zope 2.7中zope.conf的基本端口參數(shù)。下面的例子中,基本端口設(shè)置為8080, 就是說Zope會運(yùn)行在8080端口上。

訪問一下http://yoursite.com:8080進(jìn)行測試。

現(xiàn)在,你需要在你的Zope的根文件夾中添加一個(gè) Virtual Host Monster 。 名稱可以任意,不過必須添加在Zope的根文件夾中,而不是Plone站點(diǎn)的根文件夾中。

你還要邊界portal_skins/plone_templates/global_cache_settings模板來阻止Plone發(fā)送出 ‘Pragma: no-cache‘ 的HTTP報(bào)頭。缺省情況下,Plone屏蔽了所有的HTTP緩存。在ZMI中找到該模板,把它定制到你的custom皮膚文件夾中?,F(xiàn)在,把它的內(nèi)容編輯成::

<metal:cacheheaders define-macro="cacheheaders"><metal:block tal:define="dummy python:request.RESPONSE.setHeader(‘Content-Type‘, ‘text/html;;charse t= %s‘ %  charset)" /><metal:block tal:define="dummy python:request.RESPONSE.setHeader(‘Content-Language‘, lang)" /><metal:block tal:define="dummy python:request.RESPONSE.setHeader(‘Expires‘, ‘Sat, 1 Jan 2000 00:00:00  GMT‘)" /></metal:cacheheaders>

好,現(xiàn)在安裝apache.(我使用的是Apache 1.3, 不過稍作調(diào)整即可適用于Apache 2).

這樣,apache會運(yùn)行在80端口上,你可以訪問http://yoursite.com的缺省頁面.

現(xiàn)在需要編輯apache的配置文件,其中有幾個(gè)需要檢查的事項(xiàng):

  1. 保證mod_proxy激活。找到載入libproxy.so模塊的語句,確保一下代碼行沒有被注釋掉:

    LoadModule proxy_module modules/libproxy.so    AddModule mod_proxy.c    
  2. 為你的域名設(shè)置一個(gè)虛擬主機(jī)VirtualHost, 該虛擬主機(jī)為了將請求傳遞給Zope,需要使用反向代理。下面的例子中的代碼可以剪切并粘貼到/etc/httpd/conf/httpd.conf配置文件的底部,你只需要編譯幾行:

    <VirtualHost *>    # A sample VirtualHost section for using Apache as a webserver    # instead of Zope.    # ServerName is the url of your website.    ServerName yoursite.com    # Add serverAlias lines for other doamin names that should    # point to this website. They will be rewritten by Apache to    # the ServerName, so that anyone going to www.yoursite.com    # will be invisibly redirected to yoursite.com in their browser.    ServerAlias www.yoursite.com    # ServerAdmin is your email address, which shows up on error    # pages when Apache cannot connect to Zope.    ServerAdmin webmaster@yoursite.com    # The ProxyPass and ProxyPassReverse lines are the magic    # ingredients. They rewite requests to http://yoursite.com and    # pass the entire request rhough to Zope on    # http://yoursite.com:8080. The VirtualHostBase ensures that    # when the page goes back to the browser, it goes out through    # Apache, and appears to have come from http://yoursite.com.    # The line is made up from:    # ProxyPass or ProxyPassReverse    # / is the url at http://yoursite.com that you wish to use to    # point to the Zope site. You could keep http://yoursite.com as a    # flat HTML site in Apache, and replace / with /zope to make    # http://yoursite/com/zope point to your zope site.    # http://yoursite.com:8080 is the address that your zope is    # running on.    # /VirtualHostBase/http/yoursite.com:80 makes sure that zope    # *thinks* it is running at http://yousite.com instead of at    # http://yoursite.com:8080. You don‘t have to do anything else    # in Zope to make this work.    # /yourplonesite is the location of your Plone Site within Zope.    # If you added a Plone Site into the root of your Zope with an id    # of ‘mysite‘, then you just change this bit to /mysite    # /VirtualHostRoot/ makes your Plone site think it is the root of the site.    ProxyPass / http://yoursite.com:8080/VirtualHostBase/http/yoursite.com:80/yourplonesite/VirtualHostRoot/    ProxyPassReverse /    http://yoursite.com:8080/VirtualHostBase/http/yoursite.com:80/yourplonesite/VirtualHostRoot/    </VirtualHost>    

現(xiàn)在重啟apache, 你應(yīng)當(dāng)能夠看到http://yoursite.com已經(jīng)變成你的Plone網(wǎng)站了。(如果你有任何問題,首先要確保/etc/httpd/modules/目錄中有l(wèi)ibproxy.so)

下載,你已經(jīng)有了一個(gè)很好的設(shè)置:Apache專門用來接受web請求,而Zope是后斷服務(wù)器。你現(xiàn)在還可以就有一個(gè)完全的虛擬主機(jī)的設(shè)置,因此你可以在只有單個(gè)IP地址的單個(gè)服務(wù)器上運(yùn)行多個(gè)不同域名的網(wǎng)站。你需要作的所有工作就是復(fù)制并編輯每個(gè)網(wǎng)站的VirtualHost部分。

現(xiàn)在,你可能想看看這樣的設(shè)置運(yùn)行速度有多快。要知道的是,至此,我們并沒有獲得任何真正的速度提速,我們只是為此進(jìn)行了一些基礎(chǔ)工作。你可以在一臺終端上使用Apache Benchmark程序來測試網(wǎng)站的速度。該程序通常在 ‘/usr/sbin/ab‘

/usr/sbin/ab -n 100 http://yousite.com/

該命令會發(fā)送100次連續(xù)的請求到你的網(wǎng)站。你應(yīng)當(dāng)注意到請求需要大約0.5-1.0秒,沒有很大的變化。雖然這樣的結(jié)果對于一個(gè)動(dòng)態(tài)頁面來說不是太糟糕,但要記住該測試提取的僅僅是一個(gè)HTML頁面。對于完整的帶有CSS、Javascript和圖片的頁面,處理時(shí)間會長挺多的。

該測試的典型的輸出結(jié)果像這樣:

Benchmarking yoursite.com (be patient).....doneServer Software: Zope/(unreleasedServer Hostname: yoursite.comServer Port: 80Document Path: /Document Length: 32560 bytesConcurrency Level: 1Time taken for tests: 68.901 secondsComplete requests: 100Failed requests: 0Broken pipe errors: 0Total transferred: 3293500 bytesHTML transferred: 3256000 bytesRequests per second: 1.45 [#/sec] (mean)Time per request: 689.01 [ms] (mean)Time per request: 689.01 [ms] (mean, across all concurrent requests)Transfer rate: 47.80 [Kbytes/sec] received

那么,我們?nèi)魏尾拍芴岣咚俣饶兀?/p>

我們能夠做的第一件事是讓Apache緩存頁面結(jié)果。由于我們采用Apache作為前端服務(wù)器,因此通過完全可以做到,我們已經(jīng)創(chuàng)建了一個(gè)帶有緩存的反向代理,也就是說,所有的Zope生成的頁面現(xiàn)在都通過Apache來傳遞給瀏覽器,并且可以被緩存起來,顯著提高頁面訪問的性能。只是現(xiàn)在我們還沒有告訴Apache要緩存任何東西。

要讓Apache知道我們希望緩存的、具有某個(gè)過期時(shí)間設(shè)置的內(nèi)容,必須安裝mod_expires。查看你的Apache模塊目錄(通常為/etc/httpd/modules)時(shí)候有mod_expires.so,然后確認(rèn)你的Apache配置文件中有下面幾行:

LoadModule expires_module modules/mod_expires.soAddModule mod_expires.c

現(xiàn)在,在你的虛擬主機(jī)部分,在</VirtualHost>行之前添加下面幾行:

# CacheRoot is the location on the filesystem to store files that# Apache caches. This directory must be created, and the user that# Apache runs as must have full write permissions to it.CacheRoot "/tmp/proxy/yoursite.com"# CacheSize determines how big this cache can get in KB. It‘s a# good idea that this number is about 30% less than the available# space in the CacheRoot directory. Here we choose to cache 10MB# of data, which is enough for a personal website, but not for# anything larger.CacheSize 10000# CacheGcInterval specifies how often (in hours) to examine the# cache and delete obsolete files.CacheGcInterval 2# CacheLastModifiedFactor allows the estimation of an expiry date# for a page if it doesn‘t have an expiry-date specified in the# HTTP headers returned from Zope. This is based on (time since# last modification * CacheLastModifiedFactor), so that content# that is ten hours old would be given an expiry date of 1 hour in# the future.CacheLastModifiedFactor 0.1# CacheDefaultExpire sets a default expiry time of 1 hour into the# future for cached pages.CacheDefaultExpire 1# CacheDirLength sets the number of characters used in directory# names for subdirectories of CacheRootCacheDirLength 2# The following definitions set expiry times for various content# types. In this list, each content type defined is cached for a# maximum period of 1 hour (3600 seconds) before it must be checked# again. Non-listed content types are not cached.ExpiresActive OnExpiresByType image/gif A3600ExpiresByType image/png A3600ExpiresByType image/jpeg A3600ExpiresByType text/css A3600ExpiresByType text/javascript A3600ExpiresByType application/x-javascript A3600ExpiresByType text/html A3600ExpiresByType text/xml A3600

完成后,保持配置文件。然后進(jìn)入/tmp文件夾,此機(jī)一個(gè)剛才你編輯的配置文件中CacheRoot定義的目錄,修改該目錄的權(quán)限為apache用戶可寫。在我們的例子中,是這樣的:

mkdir /tmp/proxymkdir /tmp/proxy/yoursite.comchown -R apache:apache /tmp/proxy/yoursite.com

現(xiàn)在重啟Apache讓修改的配置生效。

至此,盡管Apache能夠處理緩存,但是還沒有緩存你的Plone網(wǎng)站中的任何頁面。我們可以用wget來測試一下HTTP響應(yīng)報(bào)文的報(bào)頭:

wget -sS --delete-after http://yoursite.com/--03:16:51-- http://yoursite.com/=> `index.html‘Resolving yoursite.com... done.Connecting to yoursite.com[127.0.0.1]:80... connected.HTTP request sent, awaiting response...1 HTTP/1.1 200 OK2 Date: Mon, 19 Jan 2004 03:16:51 GMT3 Server: Zope/(unreleased version, python 2.3.2, linux2) ZServer/1.1 Plone/2.0-RC34 Vary: Accept-Encoding5 Content-Length: 325606 Content-Language:7 Expires: Mon, 19 Jan 2004 04:16:52 GMT8 Etag:9 Cache-Control: max-age=360010 Content-Type: text/html;charset=utf-811 X-Cache: MISS from yoursite.com12 Connection: close

注意X-Cache報(bào)頭顯示緩存標(biāo)志為MISS(緩存中沒有的標(biāo)志).首次訪問一個(gè)頁面時(shí)會遇到這樣的情況(因?yàn)樵擁撁娴膬?nèi)容尚未被緩存),如果緩存正常的話,在后續(xù)對該頁面的請求中,我們會遇到HIT(在緩存中的標(biāo)志)。

接下來,在Apache成為一個(gè)有用的緩存器之前,需要設(shè)置你得內(nèi)容頁面的HTTP報(bào)頭的屬性,這樣Zope就會告訴Apache哪些東西需要緩存,哪些不要緩存。不幸的是,由于Zope的Accelrated HTTP Cache Mangaer中有一個(gè)尚未解決的bug,設(shè)置工作比設(shè)想的要復(fù)雜一些。

首先,你需要編輯Accelerated HTTP Cache Manager的源代碼。即Zope目錄中的lib/python/Products/StandardCacheManagers/AcceleratedHTTPCacheManager.py.

把ZCache_set函數(shù)的最后部分(在101行附近)改為:

# Set HTTP Expires and Cache-Control headersseconds=self.intervalexpires=rfc1123_date(time.time() + seconds)# note that in the original, this line was commented out.RESPONSE.setHeader(‘Last-Modified‘,rfc1123_date(time.time()))RESPONSE.setHeader(‘Cache-Control‘, ‘max-age=%d‘ % seconds)RESPONSE.setHeader(‘Expires‘, expires)

這樣就能夠確保Zope返回一個(gè)有效的Last-Modified HTTP報(bào)頭。如果沒有這樣修改,緩存會假設(shè)你的內(nèi)容是動(dòng)態(tài)生成的,不適合進(jìn)行緩存。

現(xiàn)在,重啟Zope使修改生效。

現(xiàn)在,你得系統(tǒng)具有了完整的緩存處理能力,接下來所要作的就是告訴你的Plone站點(diǎn)的Accelerated HTTP Cache Manager 應(yīng)當(dāng)緩存哪些內(nèi)容。

用管理員權(quán)限的用戶登入Zope站點(diǎn),在ZMI中進(jìn)入Plone。點(diǎn)擊HTTPCache,查看Associate頁簽。注意,當(dāng)前還沒有任何相關(guān)的內(nèi)容。

When associating items with the HTTPCache, you‘re not associating content items, instead you associate the different views available. This means that you can ensure that your view template is cached, but edit templates are not. Ensuring that the options All for Locate Cacheable Objects

在關(guān)聯(lián)HTTPCache內(nèi)容條目時(shí),你并不是把內(nèi)容條目關(guān)聯(lián)起來,二十把不同的可用的視圖關(guān)聯(lián)起來。就是說你可以確認(rèn)你得視圖模板被緩存起來,而編輯模板沒有被緩存起來。需要確認(rèn)的是選擇Locate Cacheable Object的ALL、types(s)的ALL、和搜索Subfolders都已經(jīng)選定,然后點(diǎn)擊Locate按鈕。稍過一會,你會看到你的網(wǎng)站中所有的皮膚元素中的一個(gè)列表。

需要特別注意的是你所選擇的那些條目。你可以緩存所有的圖片、文件、CSS和所有的JavaScripts.此外,你應(yīng)當(dāng)確認(rèn)所有內(nèi)容類型的view模板被緩存(比如,新聞項(xiàng)的newsitem_view)。特別注意的是在另一個(gè)皮膚文件夾中定制的那些條目。

現(xiàn)在,你應(yīng)當(dāng)有了一個(gè)非常長的緩存項(xiàng)列表,點(diǎn)擊SAVE保存修改。

假設(shè)你已經(jīng)正確完成上面的工作,你會發(fā)現(xiàn)Apache已經(jīng)開始緩存你的頁面。我們使用wget來測試,其輸出的HTTP響應(yīng)報(bào)頭如下:

wget -sS --delete-after http://yoursite.com/--03:28:46-- http://yoursite.com/=> `index.html‘Resolving yoursite.com... done.Connecting to poked.org[217.199.181.94]:80... connected.HTTP request sent, awaiting response...1 HTTP/1.1 200 OK2 Date: Mon, 19 Jan 2004 03:28:46 GMT3 Server: Zope/(unreleased version, python 2.3.2, linux2) ZServer/1.1 Plone/2.0-RC34 Vary: Accept-Encoding5 Content-Length: 321256 Expires: Mon, 19 Jan 2004 04:28:43 GMT7 Last-Modified: Mon, 19 Jan 2004 03:28:43 GMT8 Cache-Control: max-age=36009 Content-Type: text/html;charset=utf-810 Age: 411 X-Cache: HIT from yoursite.com12 Connection: close

注意,下載X-Cache的報(bào)頭為cache HIT。這正是我們要的結(jié)果。

既然Apache已經(jīng)緩存了你的Plone頁面,你就可以測試一下,看看有什么不同。還是使用Apache Benchmark工具,我們可以這樣測試:

/usr/sbin/ab -n 100 http://yoursite.com/Benchmarking poked.org (be patient).....doneServer Software: Zope/(unreleasedServer Hostname: yoursite.comServer Port: 80Document Path: /Document Length: 32125 bytesConcurrency Level: 1Time taken for tests: 0.116 secondsComplete requests: 100Failed requests: 0Broken pipe errors: 0Total transferred: 3252200 bytesHTML transferred: 3212500 bytesRequests per second: 862.07 [#/sec] (mean)Time per request: 1.16 [ms] (mean)Time per request: 1.16 [ms] (mean, across all concurrent requests)Transfer rate: 28036.21 [Kbytes/sec] received

Note particulary the time taken for this test: 0.116 seconds, or a much healtier 0.0016 seconds per request! This gives some indication of how fast this site will be capable of running.

特別注意該測試使用的時(shí)間:0.116秒,或者是更有價(jià)值的每個(gè)請求的處理時(shí)間為0.0016!這是網(wǎng)站能夠運(yùn)行有多快的指標(biāo)。

使用Apache Benchmark連續(xù)測試100次請求難以真正的評估出你的網(wǎng)站的運(yùn)行速度,不過,要真正的模擬評估,需要使用并發(fā)特性,他可以讓你同時(shí)發(fā)送請求。本例中ab用同時(shí)100個(gè)請求的方式共進(jìn)行10000次的請求。這是相當(dāng)于企業(yè)級的中/大型網(wǎng)站的負(fù)載量:

/usr/sbin/ab -n 100000 -c 100 http://yoursite.com/Benchmarking poked.org (be patient)Server Software: Zope/(unreleasedServer Hostname: poked.orgServer Port: 80Document Path: /Document Length: 32125 bytesConcurrency Level: 100Time taken for tests: 115.732 secondsComplete requests: 100000Failed requests: 0Broken pipe errors: 0Total transferred: -1041856680 bytesHTML transferred: -1081567796 bytesRequests per second: 864.07 [#/sec] (mean)Time per request: 115.73 [ms] (mean)Time per request: 1.16 [ms] (mean, across all concurrent requests)Transfer rate: -9002.32 [Kbytes/sec] received

These results show that the combination of Apache and Zope is capable of serving 100000 requests in just under 2 minutes. It‘s worth pointing out again that this is on a 1.8GHz Intel Celeron with only 128MB of RAM, running a basic Redhat 7.3 setup, which is very, very slow for a production server. On a typical Dual Intel Xeon 2.4GHz server with 1GB of RAM, expect a speed increase of over 100%.

該結(jié)果顯示Apache和Zope的組合能夠在2分鐘內(nèi)處理100000個(gè)請求。值對一提的是這是在一臺運(yùn)行基本Redhat7.3配置的、1.8GHz僅有128MB內(nèi)存的IntelCeleron服務(wù)器,這對于一個(gè)生產(chǎn)服務(wù)器來說是非常、非常慢的。在一臺典型的雙Intel Xeon 2.4GHz CPU、1GB內(nèi)存的服務(wù)器上,處理速度可以提高超過100%。

值對一提的是這樣的緩存是有一定的局限的。把Last-Modified報(bào)頭設(shè)置成頁面提取的時(shí)間,并且把最大時(shí)效設(shè)置為3600秒,該網(wǎng)站中的所有內(nèi)容的生命周期都是1個(gè)小時(shí)。這就是說在最壞情況下,該網(wǎng)站的更新會在一個(gè)小時(shí)后才發(fā)生。這可以通過強(qiáng)制對某個(gè)特定頁面進(jìn)行緩存校驗(yàn)來解決,只需要在瀏覽器中進(jìn)行CTRL-刷新頁面即可。

另一個(gè)局限在于,如果你使用你的主域名來登入和編輯你的Plone網(wǎng)站,你可能會在瀏覽器中遇到一些奇怪的情況,比如無法正確緩存報(bào)頭。一個(gè)簡單的辦法是為需要編輯網(wǎng)站的用戶添加一個(gè)之域,比如cms.yoursite.com。這樣,在你的Apache配置文件中,只需要為你得CMS簡單新建一個(gè)沒有任何緩存設(shè)置的VirtualHost部分。:

 <VirtualHost *>ServerName cms.yoursite.comServerAdmin webmaster@yoursite.comProxyPass /   http://cms.yoursite.com:8080/VirtualHostBase/http/cms.yoursite.com:80/yourplonesite/VirtualHostRoot/ProxyPassReverse /  http://cms.yoursite.com:8080/VirtualHostBase/http/cms.yoursite.com:80/yourplonesite/VirtualHostRoot/</VirtualHost>

這樣,任何需要編輯網(wǎng)站內(nèi)容的人都會整個(gè)繞過緩存。

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
關(guān)于Python的一些介紹和資源
幾個(gè)國外開源CMS系統(tǒng)比較
HTTP調(diào)試工具:Fiddler 介紹
性能計(jì)數(shù)器參考
fiddler使用介紹
Squid.conf配置文件詳解
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服