/sbin/service tomcat restart

/webagme/tomcat/bin/catalina.sh start

1.如何調(diào)整tomcat的占用內(nèi)存

A:方法如下:

1.linux 下編輯tomcat安裝目錄下的bin目錄下的catalina.sh文件,windows下為catalina.bat

vi catalina.sh

2.查找到tomcat內(nèi)存參數(shù)一行:/ JAVA_OPTS,如果找不到則在第一行寫上

3.將JAVA_OPTS="-Xms1024m –Xmx1520m"一行的兩個(gè)參數(shù)依據(jù)服務(wù)器實(shí)際內(nèi)存數(shù)量分別進(jìn)行更改:

– Xms為tomcat啟動(dòng)初始內(nèi)存,一般為服務(wù)器開機(jī)后可用空閑內(nèi)存減去100M

– Xmx為tomcat最大占用內(nèi)存,一般為服務(wù)器開機(jī)后可用空閑內(nèi)存減去50M

一般說來,您應(yīng)該使用物理內(nèi)存的 80% %u4F5C為堆大小。

說明:以上兩個(gè)參數(shù)關(guān)系到tomcat承受的訪問性能,但也要根據(jù)服務(wù)器實(shí)際內(nèi)存情況設(shè)定。

有人建議Xms和Xmx的值取成一樣比較好,說是可以加快內(nèi)存回收速度。但未經(jīng)本人驗(yàn)證過。有興趣可以試試。

 

這兩個(gè)值的大小一般根據(jù)需要進(jìn)行配置。初始化堆的大小執(zhí)行了虛擬機(jī)在啟動(dòng)時(shí)向系統(tǒng)申請(qǐng)的內(nèi)存的大小。一般而言,這個(gè)參數(shù)不重要。但是有的應(yīng)用程式在大負(fù)載的情況下會(huì)急劇地占用更多的內(nèi)存,此時(shí)這個(gè)參數(shù)就是顯得很重要,假如虛擬機(jī)啟動(dòng)時(shí)配置使用的內(nèi)存比較小而在這種情況下有許多對(duì)象進(jìn)行初始化,虛擬機(jī)就必須重復(fù)地增加內(nèi)存來滿足使用。由于這種原因,我們一般把-Xms和-Xmx設(shè)為相同大,而堆的最大值受限于系統(tǒng)使用的物理內(nèi)存。一般使用數(shù)據(jù)量較大的應(yīng)用程式會(huì)使用持久對(duì)象,內(nèi)存使用有可能迅速地增長。當(dāng)應(yīng)用程式需要的內(nèi)存超出堆的最大值時(shí)虛擬機(jī)就會(huì)提示內(nèi)存溢出,并且導(dǎo)致應(yīng)用服務(wù)崩潰。因此一般建議堆的最大值配置為可用內(nèi)存的最大值的80%%u3002

Tomcat默認(rèn)能夠使用的內(nèi)存為128MB,在較大型的應(yīng)用項(xiàng)目中,這點(diǎn)內(nèi)存是不夠的,需要調(diào)大。

Windows下,在文檔/bin/catalina.bat,Unix下,在文檔/bin/catalina.sh的前面,增加如下配置:

JAVA_OPTS=\\\’-Xms【初始化內(nèi)存大小】 -Xmx【能夠使用的最大內(nèi)存】\\\’

需要把這個(gè)兩個(gè)參數(shù)值調(diào)大。例如:

JAVA_OPTS=\\\’-Xms256m -Xmx512m\\\’

表示初始化內(nèi)存為256MB,能夠使用的最大內(nèi)存為512MB。

另外需要考慮的是Java提供的垃圾回收機(jī)制。虛擬機(jī)的堆大小決定了虛擬機(jī)花費(fèi)在收集垃圾上的時(shí)間和頻度。收集垃圾能夠接受的速度和應(yīng)用有關(guān),應(yīng)該通過分析實(shí)際的垃圾收集的時(shí)間和頻率來調(diào)整。假如堆的大小很大,那么完全垃圾收集就會(huì)很慢,但是頻度會(huì)降低。假如您把堆的大小和內(nèi)存的需要一致,完全收集就很快,但是會(huì)更加頻繁。調(diào)整堆大小的的目的是最小化垃圾收集的時(shí)間,以在特定的時(shí)間內(nèi)最大化處理客戶的請(qǐng)求。在基準(zhǔn)測(cè)試的時(shí)候,為確保最好的性能,要把堆的大小設(shè)大,確保垃圾收集不在整個(gè)基準(zhǔn)測(cè)試的過程中出現(xiàn)。

假如系統(tǒng)花費(fèi)很多的時(shí)間收集垃圾,請(qǐng)減小堆大小。一次完全的垃圾收集應(yīng)該不超過 3-5 秒。假如垃圾收集成為瓶頸,那么需要指定代的大小,檢查垃圾收集的周詳輸出,研究 垃圾收集參數(shù)對(duì)性能的影響。一般說來,您應(yīng)該使用物理內(nèi)存的 80% %u4F5C為堆大小。當(dāng)增加處理器時(shí),記得增加內(nèi)存,因?yàn)榉峙淠軌虿⑿羞M(jìn)行,而垃圾收集不是并行的。

 

 

2.如何調(diào)整tomcat的線程參數(shù)

A:方法如下:

5.編輯tomcat安裝目錄下的conf目錄下的server.xml文件

在tomcat配置文件server.xml中的<Connector />配置中,和連接數(shù)相關(guān)的參數(shù)有:

maxThreads="150" 表示最多同時(shí)處理150個(gè)連接,Tomcat使用線程來處理接收的每個(gè)請(qǐng)求。這個(gè)值表示Tomcat可創(chuàng)建的最大的線程數(shù)。默認(rèn)值200。
minSpareThreads="25" 表示即使沒有人使用也開這么多空線程等待
maxSpareThreads="75" 表示如果最多可以空75個(gè)線程,例如某時(shí)刻有80人訪問,之后沒有人訪問了,則tomcat不會(huì)保留80個(gè)空線程,而是關(guān)閉5個(gè)空的。 (一旦創(chuàng)建的線程超過這個(gè)值,Tomcat就會(huì)關(guān)閉不再需要的socket線程。默認(rèn)值50。

acceptCount="100" 當(dāng)同時(shí)連接的人數(shù)達(dá)到maxThreads時(shí),還可以接收排隊(duì)的連接數(shù)量,超過這個(gè)連接的則直接返回拒絕連接。(指定當(dāng)任何能夠使用的處理請(qǐng)求的線程數(shù)都被使用時(shí),能夠放到處理隊(duì)列中的請(qǐng)求數(shù),超過這個(gè)數(shù)的請(qǐng)求將不予處理。默認(rèn)值100。 )

其中和最大連接數(shù)相關(guān)的參數(shù)為maxThreads和acceptCount。如果要加大并發(fā)連接數(shù),應(yīng)同時(shí)加大這兩個(gè)參數(shù)。
web server允許的最大連接數(shù)還受制于操作系統(tǒng)的內(nèi)核參數(shù)設(shè)置,通常Windows是2000個(gè)左右,Linux是1000個(gè)左右。tomcat5中的配置示例:
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
acceptCount="100"/>

主要是調(diào)整maxThreads 和acceptCount的值
對(duì)于其他端口的偵聽配置,以此類推。

在tomcat配置文檔server.xml中的配置中,和連接數(shù)相關(guān)的其他參數(shù)有:

enableLookups:

是否反查域名,默認(rèn)值為true。為了提高處理能力,應(yīng)配置為false

connnectionTimeout:

網(wǎng)絡(luò)連接超時(shí),默認(rèn)值60000,單位:毫秒。配置為0表示永不超時(shí),這樣配置有隱患的。通常可配置為30000毫秒。

maxKeepAliveRequests:

nginx動(dòng)態(tài)的轉(zhuǎn)給tomcat,nginx是不能keepalive的,而tomcat端默認(rèn)開啟了keepalive,會(huì)等待keepalive的timeout,默認(rèn)不設(shè)置就是使用connectionTimeout。
所以必須設(shè)置tomcat的超時(shí)時(shí)間,并關(guān)閉tomcat的keepalive。否則會(huì)產(chǎn)生大量tomcat的socket timewait。
maxKeepAliveRequests="1"就可以避免tomcat產(chǎn)生大量的TIME_WAIT連接,從而從一定程度上避免tomcat假死。
試試設(shè)置tomcat/conf/server.xml:

maxKeepAliveRequests="1"
connectionTimeout="20000"

maxKeepAliveRequests="1"表示每個(gè)連接只響應(yīng)一次就關(guān)閉,這樣就不會(huì)等待timeout了。

 

<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="30000" maxKeepAliveRequests="1"
redirectPort="8443" bufferSize="8192" sockedBuffer="65536" acceptCount="200"/>

bufferSize:

輸入流緩沖大小,默認(rèn)值2048 bytes。

compression:

壓縮傳輸,取值on/off/force,默認(rèn)值off。

3、tomcat中如何禁止和允許列目錄下的文檔

在{tomcat_home}/conf/web.xml中,把listings參數(shù)配置成false即可,如下:

<servlet>

<init-param>
<param-name>listings</param-name>
<param-value>false</param-value>
</init-param>

</servlet>
4、tomcat中如何禁止和允許主機(jī)或IP地址訪問
<Host name="localhost" …>

<Valve className="org.apache.catalina.valves.RemoteHostValve"
allow="*.mycompany.com,www.yourcompany.com"/>
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
deny="192.168.1.*"/>

</Host>

cat /webgame/tomcat/conf/server.xml


<?xml version=\\\’1.0\\\’ encoding=\\\’utf-8\\\’?>
<!–
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
–>
<!– Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
–>
<Server port="8005" shutdown="SHUTDOWN">

<!–APR library loader. Documentation at /docs/apr.html –>
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!–Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html –>
<Listener className="org.apache.catalina.core.JasperListener" />
<!– JMX Support for the Tomcat server. Documentation at /docs/non-existent.html –>
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<!– Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
–>
<GlobalNamingResources>
<!– Editable user database that can also be used by
UserDatabaseRealm to authenticate users
–>
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
deion="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!– A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
–>
<Service name="Catalina">

<!–The connectors can use a shared executor, you can define one or more named thread pools–>
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="500" minSpareThreads="50" maxIdleTime="60000"/>

<!– A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
JavaHTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
–>
<!–
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" maxThreads="500"/>
–>
<!– A "Connector" using the shared thread pool–>
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" maxKeepAliveRequests="1"/>
<!– Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation –>
<!–
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
–>

<!– Define an AJP 1.3 Connector on port 8009 –>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

<!– An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html –>

<!– You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
–>
<Engine name="Catalina" defaultHost="localhost">

<!–For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) –>
<!–
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
–>

<!– The request dumper valve dumps useful debugging information about
the request and response data received and sent by Tomcat.
Documentation at: /docs/config/valve.html –>
<!–
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
–>

<!– This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. –>
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<!– Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
–>
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<!– SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html –>
<!–
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
–>

<!– Access log processes all example.
Documentation at: /docs/config/valve.html –>
<!–
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
–>

</Host>
</Engine>
</Service>
</Server>

參考文檔:Tomcat調(diào)優(yōu)配置技巧集錦

 

更多關(guān)于云服務(wù)器域名注冊(cè),虛擬主機(jī)的問題,請(qǐng)?jiān)L問三五互聯(lián)官網(wǎng):m.shinetop.cn

贊(0)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。郵箱:3140448839@qq.com。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明出處:三五互聯(lián)知識(shí)庫 » Tomcat 優(yōu)化-------------轉(zhuǎn)載

登錄

找回密碼

注冊(cè)

主站蜘蛛池模板: av天堂久久天堂av| 黑人大荫道bbwbbb高潮潮喷| 国产精品亚洲mnbav网站| 国产大学生自拍三级视频| 国产精品熟女孕妇一区二区| 秋霞电影院午夜无码免费视频| 久久99热只有频精品8| 亚洲自偷自拍熟女另类| 91精品乱码一区二区三区| 国产成人精品一区二三区| а∨天堂一区中文字幕| 通州市| 中文字幕日韩有码第一页| 又湿又紧又大又爽A视频男| 久久亚洲精品11p| 亚洲伊人久久综合成人| 熟女精品色一区二区三区| 国内精品久久久久影院日本| 成人动漫综合网| 成人拍拍拍无遮挡免费视频| 日本少妇被黑人xxxxx| 久久一亚色院精品全部免费| 色欲AV无码一区二区人妻| 欧洲精品色在线观看| 在线免费不卡视频| 日韩V欧美V中文在线| 精品国产午夜福利理论片| VA在线看国产免费| 大邑县| 国产欧美精品一区二区三区-老狼| 伊人久久大香线蕉综合观| 久九九精品免费视频| 国产爆乳无码视频在线观看3| 国产性一交一乱一伦一色一情 | 亚洲护士一区二区三区| 日本午夜精品一区二区三区电影| 狠狠色综合播放一区二区| 国产精品国三级国产av| 亚洲第一成人网站| 玩弄放荡人妻少妇系列| 亚洲一二区在线视频播放|