Professional Documents
Culture Documents
Andrig T Miller
Global Platform Director, Red Hat, Inc.
June, 2010
Agenda
!at "e "ill co#er...
J'M Tuning.
.onnection %ooling.
T!read %ool&.
/b0ect1com%onent %ool&.
+ogging.
.ac!ing.
Connection Pooling
Databa&e connection& are e2%en&i#e to &etu% and tear
do"n...
Rel3 on t!e data &ource definition& 3ou can &etu% in t!e de%lo3
director3 of t!e $AP, and utili5e t!e connection %ool &etting&.
A &mall %ool "ill t!rottle t!e a%%lication a& t!e re4ue&t "ill 4ueue for
a default of *0,000 milli&econd& 7*0 &econd&8 before gi#ing u%.
T!e !tt%d t!read %ool in J)o&& eb i& defined in &er#er.2ml file under
:&er#er;1de%lo310bo&&("eb(&ar.
T!e AJP t!read %ool i& al&o defined in t!e &ame file, 0u&t in it& connector
&ection.
T!ere i& al&o a T.P t!read %ool for remote me&&aging client&.
?or t!o&e remote client&, 3ou &et a client t!read %ool t!at %ool& t!e T.P
&oc-et& #ia &er#er;de%lo31me&&aging1remoting(bi&oc-et(&er#ice.2ml.
?or in J'M client&, all t!e %roce&&ing "ill occur on t!e J.A t!read %ool
7or-Manager8.
/ne note !ere, i& t!at if 3ou !a#e a me&&age dri#en bean, t!at in#o-e& ot!er
bean&, &uc! a& &tatele&& &e&&ion bean&, t!o&e bean& "ill al&o run on t!e J.A
t!read %ool.
Thread Pooling (Continued)
T!read %ool& need to be &i5ed a%%ro%riatel3 for t!e
"or-load...
If 3our client& are in t!e &ame J'M t!e3 "ill run on "!ate#er
t!read %ool t!e3 are alread3 on.
T!ere are t"o t3%e& of %ool& for $J) *, one i& called t!e
T!read+ocalPool, and t!e ot!er i& called t!e >trictMa2Pool.
T!e default& are for >tatele&& and >tateful >e&&ion )ean& to u&e t!e
T!read+ocalPool.
T!i& %ool actuall3 obe3& a ma2imum, "ill 4ueue u% re4ue&t& "!en t!at
ma2imum !a& been reac!ed, and "ill time out an3t!ing in t!e 4ueue if t!ere
i& not an a#ailable reference from t!e %ool.
T!i& i& great for de#elo%ment, e&%eciall3 "it!in t!e ID$, a& 3ou get
all t!e log me&&age& to &!o" in t!e ID$ con&ole #ie".
In t!e $AP, t!ere i& a ne" configuration, called %roduction, and t!e
con&ole logging i& alread3 turned off in t!at configuration.
T!e le&& 3ou log, t!e le&& I1/ "ill be generated, and t!e better t!e
o#erall t!roug!%ut "ill be.
%ogging (Continued)
6our a%%lication "ill create all t!e &tring ob0ect& for eac! of t!e log
&tatement& and +ogC0 create& t!e +ogging$#ent ob0ect for eac! log
&tatement, regardle&& of t!e log le#el t!at i& &et.
I !a#e %er&onall3 &een it u&ed to cac!e %roduct catalog &earc! re&ult&, "it!
dramatic %erformance im%ro#ement&.
<&eful "!ere re&ult& don,t c!ange muc!, but are e2%en&i#e to generate.
)3 far, one of t!e ea&ie&t %otential %erformance en!ancement& 3ou can ma-e i&
cac!ing of $J) * entitie&.
6ou define cac!e %ro#ider in %er&i&tence.2ml t!at 3ou de%lo3 "it! 3our $J) * a%%lication, and 3ou
u&e t!e D.ac!e annotation on t!e bean& 3ou "ant cac!ed. /n t!e D.ac!ed annotation, 3ou
&%ecif3 t!e u&age being one of t!e follo"ingE
&A'(')E be careful "it! cac!e &i5e and e#iction %olic3, 3ou onl3 !a#e &o
muc! !ea% &%ace.
&A'(')E cac!ing i& not a &il#er bullet, and can &ometime& reduce t!roug!%ut.
Example persistence*xml
<&ersistence xmlns./htt&://ja$a%sun%com/xml/ns/&ersistence/
xmlns:xsi./htt&://'''%'!%or(/7""5/CMLSchema-instance/
xsi:schemaLocation./htt&://ja$a%sun%com/xml/ns/&ersistence
htt&://ja$a%sun%com/xml/ns/&ersistence/&ersistenceI5I"%xsd/
$ersion./5%"/>
<&ersistence-unit name./ser$ices/ transaction-ty&e./=+</>
<&ro$ider>or(%hibernate%ejb%*ibernate,ersistence</&ro$ider>
<jta-data-source>ja$a:/MySQLDS</jta-data-source>
<&ro&erties>
%%%
<propert/ name()'i2ernate5cac'e5re6ion5factor/"class)
3alue()or65'i2ernate5cac'e572c*58n&i%ultiplexe&89ossCac'eRe6ion:actor/)/>
<propert/ name(;'i2ernate5cac'e5re6ion572c*5cac'efactor/)
3alue()7a3a<Cac'e%ana6er)/>
<propert/ name()'i2ernate5cac'e5use"secon&"le3el"cac'e)
<propert/ name()'i2ernate5cac'e5re6ion572c*5cf65entit/) 3alue()m3cc-entit/)/>
<propert/ name()'i2ernate5cac'e5re6ion"prefix) 3alue()ser3ices)/>
%%%
</&ro&erties>
</&ersistence-unit>
</&ersistence>
There are actually four different cache region factory classes. Besides
JndiMultiplexedJBossCacheRegionFactory, there is also
MultiplexedJBossCacheRegionFactory, SharedJBossCacheRegionFactory and
JndiSharedJBossCacheRegionFactory. You should consult the Hiernate docu!entation
aout the differences et"een the three.
J+, Tuning
Default memor3 %age &i5e i& t3%icall3 CF). !en 3ou are
addre&&ing large amount& of memor3 t!i& 4uic-l3 add& u% to lot&
of memor3 %age&.
$#en 0u&t one gigab3te of memor3, re4uire& 2G2, 1CC memor3 %age&H
All t!e ma0or J'M,& &u%%ort large memor3 %age& on +inu2, but it&
a little tric-ier to &etu% t!an one "ould t!in-.
<&e t!e GC(bit J'M "!ene#er 3ou !a#e a more t!an CG) of
memor3 a#ailable to 3ou.
RH$+ doe& let 3ou allocate large %age& on t!e *2(bit />, but 3ou get
an illegal argument "!en &tarting t!e J'M.
T!e >un J'M, a& "ell a& /%enJDF, re4uire& t!e follo"ing
o%tion, %a&&ed on t!e command(line, to u&e large %age&E
(@@EJ<&e+argePage&
(@@EJAggre&&i#e/%t&.
T!i& o%tion on t!e >un and /%enJDF 1.G J'M,& turn& on additional Hot>%ot
o%timi5ation& t!at !a#e 3et to be made default.
(@@EJDo$&ca%eAnal3&i&.
9ot a general o%timi5ation t!at I "ould rel3 on for an3t!ing out&ide of t!e
$AP "it!out te&ting it fir&t.
$&ca%e Anal3&i& determine& if ob0ect& are acce&&ed in multi%le t!read& or a &ingle t!read. If
a &ingle t!read, t!en it Ae&ca%e&B t!e ob0ect ma-ing it local.
T!i& !a& t!e affect of reducing loc-ing in man3 ca&e& 7im%ro#ing multi(core t!roug!%ut8, and
reducing garbage collection o#er!ead.
T!e more read inten&i#e 3ou are, t!e more cac!e !el%&.
/f cour&e, if 3ou are "rite !ea#3, or t!e data &et i& &o large 7e.g. data
"are!ou&e8, t!en a large cac!e "on,t !el%, and "ill be &lo"er.
Mo&t a%%lication& I !a#e &een o#er t!e %a&t 10 3ear& are read
inten&i#e.
T!i& tend& to be true, due to t!e fact t!at mo&t a%%lication& dri#e t!eir
bu&ine&& logic b3 reading data from t!e databa&e, #er&u& being !ard
coded.
T!e >un J'M, a& "ell a& /%enJDF, re4uire& t!e follo"ing
o%tion, %a&&ed on t!e command(line, to u&e large %age&E
-CC:J;seLar(e,a(es
T!e >un in&truction& lea#e it at t!at and 3ou "ill mo&t li-el3 get t!e follo"ing
errorE
8ernel%shmmax . n
!ere n i& e4ual to t!e number of b3te& of t!e ma2imum &!ared memor3
&egment allo"ed on t!e &3&tem. 6ou &!ould &et it at lea&t to t!e &i5e of t!e
large&t !ea% &i5e 3ou "ant to u&e for t!e J'M, or alternati#el3 3ou can &et it to
t!e total amount of memor3 in t!e &3&tem.
$m%nrIhu(e&a(es . n
!ere n i& e4ual to t!e number of large %age&. 6ou "ill need to loo- u% t!e large
%age &i5e in /&roc/memin9o.
$m%hu(eItlbIshmI(rou& . gid
!ere gid i& a &!ared grou% id for t!e u&er& 3ou "ant to !a#e acce&& to t!e large
%age&.
Appendix1 %arge Page ,emor2 Setup (%inux)
In /etc/security/limits%con9
!ere n i& t!e number of %age& from $m%nrIhu(e&a(es N t!e %age &i5e in F)
from /&roc/memin9o.
6ou can no" enter t!e command sysctl -&, and e#er3t!ing "ill
be &et and &ur#i#e a reboot.
6ou can tell t!at t!e large %age& are allocated b3 loo-ing at
/&roc/memin9o, and &eeing a non(5ero #alue for *u(e,a(esI+otal.
T!i& ma3 fail "it!out a reboot, becau&e "!en t!e /> allocate& t!e&e %age&, it
mu&t find contiguou& memor3 for t!em.
*u(e&a(essi4e: 7":0LB
/etc/sysctl%con9
8ernel%shmmax . 0M066!:M67
$m%hu(etlbIshmI(rou& . M"5
$m%nrIhu(e&a(es . !"N7
102CN102CN102CNK O KIKPP*CIP2
/etc/security/limits%con9
*u(e,a(esI?s$d: 5507
I !a#e run into >$ +inu2 %olicie& t!at don,t allo" a%%lication&
li-e t!e J'M to acce&& t!e &!ared memor3 &egment.
Good luc-H