jboss performance tuning part

Upload: selvenpillai

Post on 01-Mar-2018

236 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/25/2019 JBoss Performance Tuning Part

    1/21

    JBoss Performance Tuning Part 1

    Performance tuningis not a silver bullet. Simply put, good system performance

    depends on: good design, good implementation, dened performance objectives,

    and performance tuning.SinceJBoss Performance tuninginvolves also tuning the environment on which

    jBoss is run, the rst tutorial will start discussing about JV settings and !S

    settings on which JBoss can produce best results. "hen we#ll see some specic JBoss

    cong settings.

    JBoss Performance Tuning Part 1

    "his tutorial is updated to the release $.% of the application server. &f you want to

    learn all about JBoss $.%'(.%').% *erformance tuning, !ptimal data *ersistence,

    +lustering tuning, eb application tuning and much more you should not miss

    theJBoss Performance tuning book

    -ead here more about the boo

    JBoss tuning tip 1: Tune the garbage collector

    !ne strength of the J/S0 platform is that it shields the developer from the

    comple%ity of memory allocation. 1owever, once garbage collection is the principal

    bottlenec, it is worth understanding some aspects of this hidden implementation

    2n object is considered garbage when it can no longer be reached from any pointer

    in the running program. "he most straightforward garbage collection algorithms

    simply iterate over every reachable object. 2ny objects left over are then

    considered garbage. "he time this approach taes is proportional to the number of

    live objects,

    "he complete address space reserved for object memory can be divided into

    the young and tenured generations.

    https://www.packtpub.com/jboss-as-5-performance-tuning/bookhttps://www.packtpub.com/jboss-as-5-performance-tuning/book
  • 7/25/2019 JBoss Performance Tuning Part

    2/21

    "he young generation consists of eden and two survivor spaces. ost objects are

    initially allocated in eden. !ne survivor space is empty at any time, and serves as

    the destination of any live objects in eden and the other survivor space during the

    ne%t copying collection. !bjects are copied between survivor spaces in this way

    until they are old enough to be tenured3copied to the tenured generation4.

    2 third generation closely related to the tenured generation is the permanent

    generation which holds data needed by the virtual machine to describe objects that

    do not have an e5uivalence at the Java language level. 6or e%ample objects

    describing classes and methods are stored in the permanent generation

    7se the the command line option -verbose:gccauses information about the heap

    and garbage collection to be printed at each collection. 6or e%ample, here is output

    from a large server application:

  • 7/25/2019 JBoss Performance Tuning Part

    3/21

    It's demonstrated

    that an application that spends 10 of its time in garbage collection can

    lose !" of its throughput #hen scaled out to $% processors

    3http:88java.sun.com8javase8technologies8hotspot8gc8gc9tuning9).html4JBoss tuning tip 2: Set -Xms and -Xmx to the same value

    By default, the virtual machine grows or shrins the heap at each collection to try to

    eep the proportion of free space to live objects at each collection within a specic

    range.

    Setting 'ms and 'm% to the same value. "his increase predictability by removing

    the most important si;ing decision from the virtual machine.

    JBoss tuning tip : !se server "#

    "he server JV is better suited to longer running applications. "o enable it simplyset the 'server option on the command line.

    JBoss tuning tip $: Turn off distributed gc

    "he -& system provides a reference counting distributed garbage collection

    algorithm. "his system wors by having the server eep trac of which clients have

    re5uested access to remote objects running on the server. hen a reference is

    made, the server mars the object as >>>>

    JBoss tuning tip %: Turn on parallel gc

    &f you have multiple proessors you can do your garbage collection with multiple

    threads. By default the parallel collector runs a collection thread per processor, that

    http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.htmlhttp://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html
  • 7/25/2019 JBoss Performance Tuning Part

    4/21

    is if you have an processor bo% then you#ll garbage collect your data with

    threads. &n order to turn on the parallel collector use the Cag '((:)*seParallel+,.

    Dou can also specify how many threads you want to dedicate to garbage collection

    using the Cag ':*arallelE+"hreads@.

    JBoss tuning tip &: 'on(t use )uge heaps* use a cluster

    ore JVs8smaller heaps can outperform fewer JVs8Farger 1eaps. So instead of

    huge heaps, use additional server nodes. Set up a JBoss cluster and balance wor

    between nodes.

    JBoss tuning tip +: 'on(t choose an heap larger then &, of .our/S memor.

    +hoose a ma%imum heap si;e not more then G>H of the memory to avoid e%cessive

    page faults and thrashing.

    JBoss tuning tip 9: Tune the Heap ratio

    "his is one of most important tuning factor: the heap ratio. "he heap ratio

    species how the amount of the total heap will be partitioned between the

    young and the tenured space. hat happens if you have lots of long lived data

    3cached data, collections 4 I maybe you#re in this situation:

  • 7/25/2019 JBoss Performance Tuning Part

    5/21

    "he problem here is that the long lived data overfows the tenured generation.

    hen a collection is needed the tenured generation is basically full of live data.

    uch of the young generation is also lled with long lived data. "he result was thata

    minor collection could not be done successfully 3there wasn#t enough room in

    the tenured generation for the anticipated promotions out of the young generation4

    so a major collection was done.

    "he major collection wored ne, but the results again was that the tenured

    generation was full of long lived data and there was long lived data in the young

    generation. "here was also free space in the young generation for more allocations,

    but the ne%t collection was again destined to be a major collection.

    his #ill eventually bring your application to cra#l .....

    By decreasing the space in the young generation and putting that space into the

    tenured generation 3a value of ew-atio larger than the default value was chosen4,

    there was enough room in the tenured generation to hold all the long lived data and

  • 7/25/2019 JBoss Performance Tuning Part

    6/21

    also space to support minor collections. "his particular application used lots of short

    lived objects so after the % mostly minor collections were done.

    /e#atiois a Cag that species the amount of the total heap that will be

    partitioned into the young generation. &t#s the tenured'generation'si;e 8 young'

    generation'si;e. 6or e%ample, setting ':ew-atio@= means that the ratio between

    the young and tenured generation is A:=

    &f you want a more precise control over the young generation : /e#i2e is the

    initial si;e of the young generation,3a/e#i2e will specify the ma%imum si;e of

    the young generation

    hat is the recommeded heap ratios I et the tenured generation to be

    approimately t#o times the si2e of the young generation4 5ith a %+B of

    63 the recommended si2es are 1%003B for the heap and 7003B for theyoung generation4

    "his recommendation is only a starting point, you have to tune from there and to do

    that you have to gather and analy;e the garbage collection statistics.

    JBoss tuning tip 10: Monitor the free memory with monitors and snapshots

    See this tips:

    1ow to monitor jboss graphically I

    1ow to monitor JBoss with snapshotsI

    JBoss tuning tip 11: Tune the Operating System

    0ach operating system sets default tuning parameters diKerently. 6or indows

    platforms, the default settings are usually suLcient. 1owever, the 7& and Finu%

    operating systems usually need to be tuned appropriately

    olaris tuning parameters:

    +hec the following "+* parameters with your sysadmin:

    8dev8tcp tcp9time9wait9interval

    http://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-monitor-jboss-graphicallyhttp://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-monitor-jboss-with-snapshotshttp://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-monitor-jboss-graphicallyhttp://www.mastertheboss.com/jboss-server/jboss-monitoring/how-to-monitor-jboss-with-snapshots
  • 7/25/2019 JBoss Performance Tuning Part

    7/21

    8dev8tcp tcp9conn9re59ma%95

    8dev8tcp tcp9conn9re59ma%95>

    8dev8tcp tcp9ip9abort9interval

    8dev8tcp tcp9eepalive9interval

    8dev8tcp tcp9re%mit9interval9initial8dev8tcp tcp9re%mit9interval9ma%

    8dev8tcp tcp9re%mit9interval9min

    8dev8tcp tcp9smallest9anon9port

    8dev8tcp tcp9%mit9hiwat

    8dev8tcp tcp9recv9hiwat

    8dev8ce instance

    8dev8ce r%9intr9time

    "ip: 7se the netstat 's '* tcp command to view all available "+* parameters.

    Set "+*'related tuning parameters using the ndd command

    0%ample: ndd 'set 8dev8tcp tcp9conn9re59ma%95 A)=$

    une 8etc8system 9lesystem

    0ach socet connection to JBoss consumes a le descriptor. "o optimi;e socet

    performance, you may need to congure your operating system to have the

    appropriate number of le descriptors.

    See solaris documentation about this parameters:

    set rlim9fd9cur

    set rlim9fd9ma%

    set tcp:tcp9conn9hash9si;e 3Solaris and M4

    set ip:ipcl9conn9hash9si;e 3Solaris A>4

    set shmsys:shminfo9shmma% ote: "his should only be set for machines that have

    at least $ EB -2 or higher.

    set autoup

    set tune9t9fsCushr

    inu tuning parameters:

    Since in Finu% everything is a le, chec the 9le-ma parameter

  • 7/25/2019 JBoss Performance Tuning Part

    8/21

    cat /proc/sys/fs/file-max

    set fs.le'ma%@A>/)$/ into 8etc8sysctl.conf

    -aise ulimit with 8etc8limits.conf 3or ulimit 'n for current session4

    &ncrease default socket send8receive bu;er

    sysctl -w net.core.rmem_default=262144

    3default socet receive buKer4

    sysctl -w net.core.wmem_default=262144

    3default socet send buKer4

    sysctl -w net.core.rmem_max=262144

    3ma% socet receive buKer4

    sysctl -w net.core.wmem_max=262144

    3ma% socet send buKer si;e4

    >>< 3for gigabit ethernet4

    N restart the interface 3ifdown eth>Oifup eth>4

    *se Big 3emory Pages

    ?efault page si;e is $PB 3usually too smallQ4

    +hec page si;e with:

    cat /proc/meminfo

    &f you see

  • 7/25/2019 JBoss Performance Tuning Part

    9/21

  • 7/25/2019 JBoss Performance Tuning Part

    10/21

    5atchout.Spea at rst with your sysadmin and ensure that the +*7 capacity

    support the increase in threads.

    5atchout.if your threads mae use of J?B+ connections you#ll probably need to

    increase also the J?B+ connection pool accordingly. 2lso verify that your 1""*

    connector is enabled to handle that amount of re5uests

    JBoss tuning tip 1: 5hec4 the 6mbedded 7eb container

    JBoss supports connectors for http, https, and ajp. "he conguration le is

    server.%ml and it#s deployed in the root of JBoss web container 3&n JBoss $./.> it#s:

  • 7/25/2019 JBoss Performance Tuning Part

    11/21

    5atch out. if you increase the ma%"hreads count you need to raise your JBoss

    "hread pool accordingly.JBoss tuning tip 1$: Turn off JSP 5ompilation in production

    JBoss application server regularly checs whether a JS* re5uires compilation to a

    servlet before e%ecuting a JS*. &n a production server, JS* les wonWt change and

    hence you can congure the settings for increased performance.

    !pen the web.%ml in deploy8jboss'web.deployer8conf folder. Foo for the jsp servlet

    in the le and modify the following F fragment as given below:

    1

    2

    3

    4

    5

    6

    7

    8

    'init-param%'param-name%development'/param-name%'param-value%false'/param-value%'/init-param%'init-param%'param-name%c!eck@nterval'/param-name%'param-value%$&&'/param-value%'/init-param%

    -eferences:

    http:88java.sun.com8javase8technologies8hotspot8gc8gc9tuning9).html

    http:88people.redhat.com8aliins8system9tuning.html

    http:88community.jboss.org8wii8JBoss2S"uningSliming

    JBoss performance tuning part %

    7ser -ating: $ 8 (

    http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.htmlhttp://people.redhat.com/alikins/system_tuning.htmlhttp://community.jboss.org/wiki/JBossASTuningSliminghttp://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.htmlhttp://people.redhat.com/alikins/system_tuning.htmlhttp://community.jboss.org/wiki/JBossASTuningSliming
  • 7/25/2019 JBoss Performance Tuning Part

    12/21

    *lease rate

    Aetails

    *ublished: A/ ?ecember />>

    "hisPerformance tuningtutorial is updated to the release $.% of the application

    server. &f you want to learn all about JBoss $.%'(.%').% *erformance tuning, !ptimal

    data *ersistence, +lustering tuning, eb application tuning and much more you

    should not miss the JBoss *erformance "uning boo.

    -ead more about the boo here

    JBoss Performance Tuning Part Tip 1!: "ots of #JB re$uests % switch to the Poo&'n(o)er

    JBoss uses -& for 0JB communication and by default creates a single thread for

    every incoming re5uest.

    hen the number of re5uests is very large this could be a bottlenec. 1owever you

    can switch from the standard jrmp service invoer to the pool invoer.

    1ow to do it I open standardjboss.%ml and nd the following fragment:

    Xinvoer'mbeanYjboss:service@invoer,type@jrmpX8invoer'mbeanY

    !n JBoss $.% you should nd $ occurrences of it: stateless'rmi'invoer, clustered'

    Vote ( -ate

    https://www.packtpub.com/jboss-as-5-performance-tuning/bookhttps://www.packtpub.com/jboss-as-5-performance-tuning/book
  • 7/25/2019 JBoss Performance Tuning Part

    13/21

    stateless'rmi'invoer, stateful'rmi'invoer,entity'rmi'invoer. ow replace this

    fragment with :

    Xinvoer'mbeanYjboss:service@invoer,type@pooledX8invoer'mbeanY

    otice you can even have a mi%ed environment: that is stateless invocation

    managed by the pool and all others by jrmp.

    &f you want to change the default attributes of your pool then open=boss-

    service4ml

    A

    /=

    $

    (

    )

    G

    MA>

    AA

    A/

    A=

    'm(eancode=)org.*(oss.invocation.pooled.server.ooled@nvoker)

    name=)*(ossservice=invokerAtype=pooled)%

    'attri(utename=)umccept,!reads)%1'/attri(ute%

    'attri(utename=)5axoolie)%$&&'/attri(ute%

    'attri(utename=)8lient5axoolie)%$&&'/attri(ute%

    'attri(utename=)ocket,imeout)%6&&&&'/attri(ute%

    'attri(utename=)erver+indddress)%9*(oss.(ind.address:'/attri(ute%

    'attri(utename=)erver+indort)%444;'/attri(ute%

    'attri(utename=)8lient8onnectddress)%9*(oss.(ind.address:'/attri(ute%

    'attri(utename=)8lient8onnectort)%&'/attri(ute%

    'attri(utename=)8lientBetry8ount)%1'/attri(ute%

    'attri(utename=)Cna(le,cpoDelay)%false'/attri(ute%

    '/m(ean%

    "here are two ey attributes for the *ooled&nvoer in regards to how many threadsare used in processing re5uests. "he rst is the /um6ccepthreads attribute.

    "he value for this attribute will determine how many threads are created to listen

    for incoming re5uests. "hese threads will be the ones that call the accept34 method

    of the server socet 3which is a blocing call and will wait there till data is received

    on the networ interface for the server socet4.

  • 7/25/2019 JBoss Performance Tuning Part

    14/21

    "he 3aPooli2e is the other ey factor: it#s the si;e of the pool containing the

    Server"hreads .

    How can MaxPoolSize become a bottleneck ? if the accept thread can not get a

    worer thread from the pool and the pool si;e has reached the a%*oolSi;e value, it

    will wait for one to become available 3instead of creating a new one4.

    Tip 1*: Ha(e you got readon&y #ntity Beans % te&& it to JBoss

    JBoss oKers a way to handle this situation by dening either an entire 0JB as being

    AA

    'enterprise-(eans%

    'entity%

    'e*(-name%5yCntity'/e*(-name%

    'met!od-attri(utes%

    'met!od%

    'met!od-name%getE'/met!od-name%

    'read-only%true'/read-only%

    '/met!od%

    'met!od-attri(utes%

    '/entity%

    '/enterprise-(eans%

    Tip 1+: ,isa-&e the hot dep&oyer in production

  • 7/25/2019 JBoss Performance Tuning Part

    15/21

    See this tip:

    ?isable hot deployment on JBoss

    Tip 1.: /onfigure the #JB container to use cache when possi-&e

    &f the 0JB container has e%clusive access to the persistent store, it doesnWt need to

    synchroni;e the in'memory bean state from the persistent store at the beginning of

    each transaction.

    So you could activate the so'called ,ommit-6 option that caches entity bean state

    between transactions. &n order to activate this option :

    A

    /

    =

    $

    (

    )

    G

    M

    A>

    AA

    A/

    A=

    A$

    A(

    A)

    AG

    '*(oss%

    'enterprise-(eans%

    'container-configurations%

    'container-configurationextends=

    )tandard 85 2.x Cntity+ean)%

    'container-name%85 2.x and 8ac!e'/container-name%

    'commit-option%'/commit-option%

    '/container-configuration%

    '/container-configurations%

    'entity%

    'e*(-name%5yCntity'/e*(-name%

    'configuration-name

    85 2.x and 8ac!e'/configuration-name%

    'met!od-attri(utes%

    'met!od%

    'met!od-name%getE'/met!od-name%

    http://www.mastertheboss.com/jboss-howto/42-jboss-config/68-configure-jboss-disable-hot-deployment-.htmlhttp://www.mastertheboss.com/jboss-howto/42-jboss-config/68-configure-jboss-disable-hot-deployment-.html
  • 7/25/2019 JBoss Performance Tuning Part

    16/21

    A

    AM

    />

    /A

    //

    /=

    'read-only%true'/read-only%

    '/met!od%

    'met!od-attri(utes%

    '/entity%

    '/*(oss%

    ip 1: *se ,ache invalidation in a ,luster for ,ommit

  • 7/25/2019 JBoss Performance Tuning Part

    17/21

    M

    A>

    AA

    A/

    A=

    'met!od-name%getE'/met!od-name%

    'read-only%true'/read-only%

    '/met!od%

    'met!od-attri(utes%

    'cac!e-invalidation%,rue'/cac!e-invalidation%

    '/entity%

    ip %0: ynchroni2e at commit time #hen possible4

    "he sync'on'commit'only element congures a performance optimi;ation that willcause entity bean state to be synchroni;ed with the database only at commit time.

    ormally the state of all the beans in a transaction would need to be synchroni;ed

    when an nder method is called or when an remove method is called :

    A

    /

    =

    $

    (

    )

    G

    'container-configuration%

    'container-name%tandard essimistic 85 2.x Cntity+ean'/container-name%

    'call-logging%false'/call-logging%

    'invoker-proxy-(inding-name%entity-pooled-invoker'/invoker-proxy-(inding-name%

    'sync-on-commit-only%true'/sync-on-commit-only%

    ....

    '/container-configuration%

    Tip 1: 2se Prepared Statement /ache:

    &n JBoss, by default,prepared statements are not cached. "o improve performance

    one can congure a prepared statement cache of an arbitrary si;e. Dou can use in

    your 'ds.%ml le the Cprepared-statement-cache-si2eD : this is the number of

    prepared statements per connection to be ept open and reused in subse5uent

    re5uests.

  • 7/25/2019 JBoss Performance Tuning Part

    18/21

    Tip : 3emo(e ser(ices you don4t need

    JBoss ships with lots of services, however you#ll seldom need to use them all. "he

    service is usually deployed as Z'service.%ml under the deploy directory. Sometimes

    it#s also deployed as .sar8.rar archive.

    &n order to remove the service, remove the le in the .jar

    1SF ?B hs5ldb'ds.%ml hs5ldb'plugin.jar, hs5ldb.jar

    ?efault JS Service jms folder jbossm5.jar

    1""* &nvoer 3tunnels -& through

    1""*4

    http'invoer.sar

    2 ?atasources jboss'%a'jdbc.rar

    J +onsole jm%'console.war

    eb +onsole management8web'console.war

    JS-'GG management8console'mgr.sar

    onitoring mail alerts monitoring'service.%ml jboss'monitoring.jar

    Schedule anager schedule'manager'service.%ml scheduler'plugin.jar, scheduler'

    plugin'e%ample.jar

    Sample Schedule service scheduler'service.%ml

  • 7/25/2019 JBoss Performance Tuning Part

    19/21

    &f you are removing a core JBoss service lie JS or 02- ?eployer then you need to

    remove it also from the=boss-service4ml :

    A

    /

    =

    $

    (

    )

    G

    M

    A>

    AA

    A/

    A=

    A$

    A(

    A)

    AG

    'm(eancode=)org.*(oss.management.*2ee.>ocal0+osserverDomain)

    name=)*(oss.management.local*2ee,ype=02CCDomainAname=5anager)%

    'attri(utename=)5ainDeployer)%*(oss.systemservice=5ainDeployer'/attri(ute%

    'attri(utename=)BDeployer)%*(oss.systemservice=erviceDeployer'/attri(ute%

    'attri(utename=)CBDeployer)%*(oss.*2eeservice=CBDeployer'/attri(ute%

    'attri(utename=)C0+Deployer)%*(oss.e*(service=C0+Deployer'/attri(ute%

    'attri(utename=)BBDeployer)%*(oss.*caservice=BBDeployer'/attri(ute%

    'attri(utename=)85Deployer)%*(oss.*caservice=8onnectionFactoryDeployer'/attri(

    'attri(utename=)GBDeployer)%*(oss.we(service=Ge(erver'/attri(ute%

    'attri(utename=)8BDeployer)%*(oss.*2eeservice=8lientDeployer'/attri(ute%

    'attri(utename=)5ailervice)%*(ossservice=5ail'/attri(ute%

    'attri(utename=)05ervice)%*(oss.mHservice=Destination5anager'/attri(ute%

    'attri(utename=)0D@ervice)%*(ossservice=aming'/attri(ute%

    'attri(utename=)0,ervice)%*(ossservice=,ransaction5anager'/attri(ute%

    'attri(utename=)?ser,ransactionervice)%*(ossservice=8lient?ser,ransaction'/a

    'attri(utename=)B5@_@@Iervice)%*(ossservice=8or(aIB+'/attri(ute%

    '/m(ean%

    Simply comment the attribute relative to the unwanted service

    Tip : Te&& &og56 to shut up 7

    el not really anyway Fog$j uses a valuable amount of time8+*7 so you had better

    remove unnecessary logs, for e%ample :

    -emove logs from +onsole

    +omment the following line in log7=4ml in order to remove logs on the +onsole:

    A 'pclass=)ol-foreground)%'root%

  • 7/25/2019 JBoss Performance Tuning Part

    20/21

    /

    =

    $

    (

    )

    'J-- 'appender-ref ref=8II>C)%'/appender-ref% --%

    'appender-refref=)F@>C)%'/appender-ref%

    '/root%

    '/p%

    remove also the relative appender:

    Xappender name@C)%'/appender-ref%

    '/root%

    '/p%'pclass=)ol-foreground)%'/p%

    -ead more about *erformance tuning boo here

    https://www.packtpub.com/jboss-as-5-performance-tuning/bookhttps://www.packtpub.com/jboss-as-5-performance-tuning/book
  • 7/25/2019 JBoss Performance Tuning Part

    21/21