Skip to main content

JBoss EAP 6 - 效能調校 (一) DataSource 的 Connection Pool

效能沒有什麼Best Practice, 反正能調整的就那些。 通常,一個程式的效能大概有70-80% 都跟程式怎麼寫的其實比較有關係。

最近我最疼愛的小貓Puji 因為膀胱結石開刀的時候過世了,心情很差請原諒我的口氣沒有很好,也沒有心情寫部落格。

Puji R.I.P.


=======================正文=======================

這個題目很多人叫我寫,可是這題目好大,這分明就是整死我咩~
所以我會分幾段慢慢寫。

  • JBoss 的 Subsystem
    • Datasource 
    • Web
    • Web Service 
    • EJB 
    • Hibernate 
    • JMS
    • JCA
  • JVM 調校
  • OS (作業系統)


先來看一下 DataSource Subsystem, DataSource 的部分主要是針對Connection Pool 做調校。

通常,程式都會需要跟資料庫界接,電腦在本機,尤其是在記憶體的運算很快,但是一旦要外部的資源連接,就是會非常的耗資源。所以現在的應用程式伺服器都會有個Pool 放一些先連接好的 資料庫connection,當程式有需要的時候就可以馬上提供,而不用花那些多餘的資源去連接資料庫。

這就是為什麼要針對Connection Pool 去做調校。

以下會討論到的參數,都是跟效能比較有關係,Datasource 還有很多參數,像是檢核connection 是否正確的,我都不會提到。如果你追求的是非常快速的效能,那我建議你一個檢核都不要加。當然,這樣就會為伺服器上面執行的程式帶來風險。這就是你要在效能與正確,安全性上面的取捨了。 (套句我朋友說的話,不可能又要馬兒好,又要馬兒不吃草的..)

最重要的調校參數就是 Connection 的 Pool 數量。(也就是那個Pool 裡面要放幾條的connection.) 這個參數是每一個應用程式都不一樣的。

min-pool-size 

Connection Pool 最少會存留的connection 數量

max-pool-size 

Connection Pool 最多可以開啓的 connection 數量

prefill

事先將connection pool 裡面建立好min-pool-size 的connection.

我的建議是觀察一下平常程式要用到的量設定為 min-pool-size 。
加上可能會衝高的最大量以及確認測試過資料庫可以承受的數量 max-pool-size 再 x 20%~30 %以上。不用擔心設的太大,反正你沒用到那麼多,connection pool 也不會真的建這麼多。

還有一個prefill 的參數,我建議是把它打開,這個參數會在JBoss EAP 一起動的時候,把connection pool 裡面的connection 先建立到connection pool 裡面。 這樣就可以減少一開始程式要連接到資料庫要消耗的時間以及資源。

還有一個比較重要的參數,就是 timeout 的參數。

blocking-timeout-millis 

這個參數是指,當你的connection pool 裡面所有的connection 都被現在跑的程式拿光光的時候,下一個程式在那裡排隊等待下一個可用connection 的時間。 超過時間就會出exception 了。(PS, 這只是等待拿到connection的時間喔~如果你很快就拿到一個connection, 可是建立的時候可能因為資料庫出問題,所以等了很久,這段的時間是不算的喔。) 預設的時間是 30秒。



idle-timeout-minutes

Connection Pool 裡面的connection 發呆很久沒人用的等待時間,如果超過這個時間 (分鐘計算喔) 都沒人來用它的話~ 那就把這個connection 關掉。 它的底層就是一個叫做  idleRemover 的thread, 大概隔一段時間就會起來scan 看看 connection time 超過idle-timeout的,如果有就關閉。所以connection 並不是一到時間就會馬上自動關閉,要等到 idleRemover scan 時才會真的關掉。 而 idleRemover 大概就是你所有 pool 的設定最小的 idle-timeout-minutes  一半的時間。



set-tx-query-timeout

是否要設定查詢的timeout 時間,當然還是以整個交易timeout 為主。 如果你的query timeout 時間還沒到, 整個transaction(交易) 就 timeout 的話,還是以transaction(交易)第一優先。

query-timeout

這個參數需要上一個 set-tx-query-timeout 設定成true 才會有作用,不然default 就是0 不會timeout. 這個參數是查詢一次要多久的時間,超過的timeout.


如果你不想要太多卡在伺服器上面的交易的話,請盡量把上面的timeout時間設短,當然,相對的程式就會出現很多timeout 的exception, 以正常來說,timeout 的時間不可過長,交易一定要比timeout使用的時間更短,如果很長的話,可能要看一下資料庫的狀態,程式寫的方式,甚至是資源根本就是不夠用。

設定的地方就在 datasource的這個subsystem下,

    
        jdbc:mysql://localhost:5432/MyDB
    
    mysql
    
        10
        30
        true
    
    
        30000
        5
        true
        30



至於可以觀察哪些數據呢,打開CLI 來看看:


[standalone@localhost:9999 statistics=pool] :read-resource(include-runtime=true)
{
    "outcome" => "success",
    "result" => {
        "ActiveCount" => "0",
        "AvailableCount" => "20",
        "AverageBlockingTime" => "0",
        "AverageCreationTime" => "0",
        "CreatedCount" => "0",
        "DestroyedCount" => "0",
        "InUseCount" => "0",
        "MaxCreationTime" => "0",
        "MaxUsedCount" => "0",
        "MaxWaitCount" => "0",
        "MaxWaitTime" => "0",
        "TimedOut" => "0",
        "TotalBlockingTime" => "0",
        "TotalCreationTime" => "0"
    }
}

主要看一下 ActiveCount, 看看目前總共有多少活著的connection, AvailableCount 看一下pool裡面是都滿了,還是Connection 大部份都借出去了. MaxUseCount 可以拿來看系統最大最巔峰的時候,開了多少的connection 出去用。 MaxCreationTime 告訴你,建立一個connection 最久花多久。如果很久的話,要查查看資料庫的資源是否夠,或是網路有問題。 如果MaxWaitCount 太高的話,可能是connection pool 太小,或是有connection leak造成要一個connection排隊排太長了等等...

或是你可以在 Console 上面看l,雖然沒有很多參數,但最主要的pool size是可以看見的。



當然,校能調校還是要觀察久一點的比較好,所以這時候拿JON來看一整個禮拜的connection pool 的設定是最棒的拉~。在CLI 上面的參數也大多都看得到。


突然想到, 如果你發現datasource 的 use-ccm 是等於 true,記得關掉,因為它很消耗資源的。

以上。



Comments

Unknown said…
McAfeecom/activate

McAfee.com/activate may be used in order to Activate McAfee Security. You may easily use the McAfee by going to the link and enter the 25 digit product key.

McAfee is an antivirus which is available worldwide for devices like Computer, Laptop or Smartphones, and McAfee is one of the best 10 Antivirus according to all reviews in last 10 years. McAfee Security is used to secure the devices from Trojans, Attacks, Malware or any other activities which may harm the devices or network. McAfee requires the minimum requirements on the devices in order to work successfully which are mentioned on the manufacturer website.
Unknown said…

brother printer support

Brother-printer-support is one of the best Brand available which offers a wide range of Brother Printers available in the market which may involve different features including high-end printing, Ethernet/Wireless Networking, LED/Color Laser Printing, White Laser Printers, LED Multiple Function Printers, LED All in one Printers and Brother Duplex Printers. Brother Printers have the friendly interface which is easy to use. There are some glitches as users still face issues or errors while installing or other Brother Printer Technical issues.
Unknown said…

roku.com/link


Roku.com/link or Roku provides the simplest solution to all your entertainment requirements. If you are game enthusiasts or like to binge watch TV series or movie, Roku is there for you. It is undoubtedly number one choice for entertainment seekers. With the wide range of top channels associated with the company like HBO, Netflix, BBC, youTube, HULU and many more, Roku showcase company’s ability to provide high-quality content. It is also very easy to use and activate, and anybody can do that easily, which probably is the reason why you came here.
When you buy a new HP printer, you try to connect it using the user manual. The manual provided by the 123.hp.com/setup manufacturer may not be in detail. Hence, our technical experts have given simple instructions that guide you through the HP Printer setup and troubleshooting issues if any. We also offer free 123hp driver (Both Basic and Full-feature) to make your printer function efficiently. The navigation is too easy such that all instructions are available on one single page. www.123.hp.com/setup
smith warner said…
Hello, I'm Smith Warner. If you are facing issues with mcafee(mcafee.com/activate), norton(norton.com/setup) and office(office.com/setup) product. then you can visit my website.
sophieturner said…

Thank for important information . I like your explanation of topic and ability to do work.I really found your post very interesting .
Activation.kaspersky.com | Kaspersky activation code | Aol Support | Install Kaspersky with Activation Code
arial said…
To get started with your Microsoft Office Installation we can help you with our entire process to setup office product online.office.com/setup

sophieturner said…

Thanks for sharing such important information your contant is very impressive. I like your explanation of topic and ability to do work.I really found your post very interesting .
Brighthouse Spectrum | Brighthouse annuities | Brighthouse pay my bill | Brighthouse financial metlife | Bright House email login | Brighthouse Webmail | Brighthouse Email | Spectrum brighthouse login
meldaresearch said…
The writers in companies that provide medicine essay writing services are engaged in extensive research to ensure that only relevant information is included by our Best Custom Research Paper Writing Services department.
OPP LOANS said…
Do you need a loan to pay off your bills? Or for your Business if yes
Email us opploansllc@gmail.com then fill this information to
register your name in our data base.

(1)Your Name:
(2)Amount needed as loan:
(3)Phone number:
(4)Duration:
(5) Male/Femele:
(6)Country

Regards.


This is a fantastic idea! I like it a lot because it's super easy for the audience to see the value of opting in. wonderful and amazing post very use full your post thanks for sharing your article
Android Application development
Web application


Your post is very good. I got to learn a lot from your post. Thank you for sharing your article for us. it is amazing post
what is seo
types of seo

A major commented factor of our nursing research papers is the ability of our writers to provide best custom research paper services services that matches the academic requirements of students.
virginiafawcett said…
The breakfast club movie review essay tells about a movie that gives a very interesting insight into life of teenagers gathered together in detention. Five people that have to spend time together are very unique and unlike others.
OPP LOANS said…
Are You In Need Of A Private Or Business Loans At 2% Rate For Various Purposes? If Yes; Contact us: opploansllc@gmail.com
Expo 2020 said…
Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.
Job in Dubai
sophieturner said…

Are you finding any technical error in your Dell product regarding your dell support assistant download , printer and laptops and so ? contact dell supportassist to fix your problems. we are here for your help. call now! we will answer your call within 60 seconds!
dell support assistant download
Jack Arona said…

You're a talented blogger. I have joined your bolster and foresee searching for a more noteworthy measure of your amazing post. Also, I have shared your site in my casual networks!


mcafee.com/Activate
mcafee.com/Activate
Office.com/setup
Office.com/setup
PlentyOfFish said…
Pof Mobile Login: Your post is very great.I read this post and this is very helpful. If You are aged between 25-34 and searching for dating apps then you must go through Plenty Of Fish which is is a popular dating website by using Pof Mobile Login
Scott Stayris said…
Thank you for sharing this post. Quickbooks is the advanced accounting software for business transactions.In QuickBooks Online Advanced, you can use the backup quickbooks online and restore the app to save online backups of your accounting data
Nancy Jones said…
I have just come across your post and I believe this is exactly what I am looking for. I want an economics assignment help
from a tutor who can guarantee me a top grade. Do you charge per page or does it depend on the bulk of the economics homework help being completed? More to that if the work is not good enough do you offer free corrections.

Nancy Jones said…
I have sent your Matlab assignment help team an email now. It just details my assignment requirements. I need a very good Matlab homework help tutor to be handling my numerical methods assignments. This is just the start because I just enrolled in a Matlab class. I, therefore, want someone who will be available and ready to deliver my work on time. If you have one very good Matlab expert then link me with them so that we can start the work immediately.
Nancy Jones said…
I need the help of an statistics assignment help in understanding the difference between two functions. The excel functions substitute and replace seem like they do the same task that is to replace the values of cells. Is there any difference between the two functions that I should know? Or can I use the two interchangeably whenever I need them? What’s your opinion as a statistics homework help tutor.

Nancy Jones said…
I have one pending Python assignment and two upcoming ones. Therefore I need a python assignment help expert this week. However, before I proceed with taking your programming assignment helpI want to know whether I will be refunded my money if my work is not submitted on time. I also other programming languages so I might also hire C Assignment Help
expert and C++ Assignment Help expert. My friend told me about one Java Assignment Help expert and I want to hire the same guy. Is it possible? Also is it possible that a single person provides entire Programming Coursework Help? Also, many online platforms never take time seriously but I want to believe you don’t belong to that class. If you promise that the quality of my assignment will be good and there will be timely delivery then I am willing to work with you.
Maria Garcia said…
Hi, other than economics assignment help are there other subjects that you cover? I am having several assignments one needs an conomics homework help
expert and the other one needs a financial expert. If you can guarantee quality work on both then I can hire you to complete them. All I am sure of is that I can hire you for the economics one but the finance one I am not sure.
Maria Garcia said…
Do you have a Ph.D. level Matlab homework help tutor? I want a very experienced person to work on my control systems project. The https://www.matlabassignmentexperts.com/Matlab assignment helpMatlab assignment help expert you assign me must be willing to complete my project within one month. Within this period I will also give him/her around two assignments to complete for me. I have sent you an email with the requirements and the topic of the project I want to be handled. Kindly send me a quotation.
Maria Garcia said…
Looking for an Statistics homework help expert? I am an SPSS tutor helping students understand the challenging topics. I understand that SPSS is very challenging and most students opt to look for help to avoid exam failure. I major in ensuring that you understand all concepts in SPSS by offering you help in:
Statistical quality control
Correlation analysis
Data validation
Non-parametric analysis
Contact me for Statistics Assignment Help.
Maria Garcia said…
I once hired an expert from your site for C Homework Help. I was pleased with it and I was told that your Python homework help tutors also develop programs outside school. I am not a student but I want a program to use in my office. The program should be able to automatically calculate employee office hours in the office and equate them with the amount payable at the end of the month. You can also provide me with a Java Homework Help expert. They too can develop the program. If needed we can also hire a C++ Homework Help expert. If you think this is possible then let’s interact more so that I can know the charges for your programming homework help. It would be great if there is someone with the knowledge of all programming languages such as a
Programming Coursework Help expert.
jasminOlivia said…
Printers are friendly tools you can find everywhere these days, whether at office or at home. They are an essential part of office supplies, giving you the ease of printing your documents any time for more information on printer goto
support.brother.com/mac
This is a very wonderful article I get so much information from your blog thank you so much for sharing this with us. I have also some useful links to share here. office.com/setup, www.office.com/setup, Office product key
daysiedarla said…
There's alternative edition of the port, to automatically trigger Youtube that's as convenient and easy to use and may be substituted into the procedure mentioned above.What that you have to accomplish is merely Open the"Preferences" from the Youtube widget onto the apparatus, select"connect with a cell device", then onto your own smartphone visit the browser and then click link Youtube.com/pair, which will bring in a code, then input the chosen code onto the television. That is always to be accomplished only to verify that your choice by simply clicking"Insert" and you're able to utilize the service later at simplicity.
youtube.com/activate
www.youtube.com/activate

daysiedarla said…
Open the Tubi program in your Samsung Television. 2. Navigate into the exact top of this Tubi home screen, and soon you visit Settings, Search, and Signal In icons. 3. Select Register. You may now find an activation code onto your own television screen. 4. On a computer system or cell browser, head to tubitv.com/activate
tubi.tv/activate | tubi.tv/activate enter code | tubi.tv/activate
12winasia.net said…
This article is very informative and useful thank you for sharing this blog with us. Vliesbehang, behang, Barok behang
12winasia.net said…
Wow, Awesome Article Thank you so much for sharing this with us such a useful information with us. Vliesbehang, behang, Barok behang
Eva Wilson said…
Being an academic writer from past 5 years providing online dissertation help to college and university students. I am dedicated in providing best online academic writing services to the college students at the affordable rates.
tianaturner03 said…
Get the basic guidelines to use and manage the Venmo login account. The manual instructions are provided to access the Venmo account on your compatible devices.
Venmo Login | Venmo Login
Logan Lerman said…
This informative read is focused on transferring your AOL Mail contacts to your Gmail account for ease, reliability and fast accessibility world-wide.
AOL Mail Login | AOL Mail Login
sophieturner said…
Learn the basic steps to access open hp printer software website without interruptions. Follow the quick and basic steps to deal with the error in the hp printer. Our experts are there for you round the clock for resolving your problems.
Open HP Printer Software | HP Support Solutions Framework | HP Officejet 4650 Wireless Setup

Popular posts from this blog

Red Hat Fuse - Announcing Fuse 7 Tech preview 3 release.

Red Hat Fuse 7.0 technical preview three is out today! On the pathway to become one of the best cloud-native integration platform, Fuse gives developer freedom to choose how they want to develop the integration solution, where they want to deploy it and capabilities to address new integration personas that do not have development experience. By supporting the three major runtime , developer is free to work on the runtime of their choice. By supporting  standalone and cloud deployment , it simplifies the complexity to distinguish between these environments, allowing application to deploy freely among the environment of your choice.  All levels of developers are welcome, you can either dive deep into creating customize complex integration logic , or using the new low code platform to quickly build a simple integration. In this Tech Preview release you get it all. Fuse Standalone Spring-boot for microservice Karaf 4 for OSGi lover JBoss EAP for JavaEE developers Fuse on Op

JBoss Fuse - Fuse workshop 101 - Part One

On my way to Hong Kong for a day of workshop on JBoss Fuse, and as I go through my Slide deck, I cannot find any decent easy workshop for beginners. Therefore I decide make a workshop that is easy for Camel first timer to get their hands dirty. The first of part of the workshop is an introduction to Camel, it first goes through what is exactly inside JBoss Fuse. For part one of the workshop, it takes your through the very basic of Camel, one of the very important component inside JBoss Fuse. Every Camel need to have a runtime container to run in, inside camel we call it a CAMEL CONTEXT.  Inside every Camel context, you can define lots of camel route and registry, don't worry about what those are, we will explain later. So inside out blueprint xml, you will see a tag called camelContext. Next up is camel route, they are a chain of command or process defined by you, as a developer. Inside the camel route, there are consumer endpoints that listens to the incoming mess