spring/hibernate mysql configuration for get best performance -


how should configure mysql driver , hibernate properties in applicaton-context.xml best performance? have suggestions improvement? , configurations?
application-context.xml

<!-- data source declaration --> <bean id="datasource" class="org.apache.commons.dbcp.basicdatasource"     destroy-method="close">     <property name="driverclassname" value="com.mysql.jdbc.driver" />     <property name="url"         value="jdbc:mysql://localhost:3306/oys?characterencoding=utf-8" />     <property name="username" value="root" />     <property name="password" value="" /> </bean>  <!-- session factory declaration --> <bean id="sessionfactory"     class="org.springframework.orm.hibernate4.localsessionfactorybean"     scope="singleton">     <property name="datasource" ref="datasource" />     <property name="packagestoscan">         <list>             <value>spring.dao</value>             <value>spring.model</value>             <value>spring.service</value>             <value>spring.other</value>         </list>     </property>     <property name="hibernateproperties">         <props>             <prop key="hibernate.dialect">org.hibernate.dialect.mysqldialect</prop>             <prop key="hibernate.show_sql">true</prop>             <prop key="hibernate.generate_statistics">true</prop>             <prop key="hibernate.cache.use_second_level_cache">true</prop>             <prop key="hibernate.cache.use_query_cache">true</prop>             <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.ehcacheregionfactory             </prop>             <prop key="hibernate.enable_lazy_load_no_trans">true</prop>             <prop key="use_sql_comments">true</prop>             <prop key="hibernate.bytecode.use_reflection_optimizer">true</prop>             <prop key="hibernate.connection.autocommit">true</prop>             <prop key="net.sf.ehcache.configurationresourcename">/myehcache.xml</prop>         </props>     </property> </bean> 

myehcache.xml

    <?xml version="1.0" encoding="utf-8"?> <ehcache xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"     xsi:nonamespaceschemalocation="ehcache.xsd" updatecheck="true"     monitoring="autodetect" dynamicconfig="true">      <diskstore path="java.io.tmpdir/ehcache" />      <defaultcache maxentrieslocalheap="10000" eternal="false"         timetoidleseconds="120" timetoliveseconds="120" diskspoolbuffersizemb="30"         maxentrieslocaldisk="10000000" diskexpirythreadintervalseconds="120"         memorystoreevictionpolicy="lru" statistics="true">         <persistence strategy="localtempswap" />     </defaultcache> m     <cache name="forexample" maxentrieslocalheap="10000" eternal="false"         timetoidleseconds="5" timetoliveseconds="10">         <persistence strategy="localtempswap" />     </cache>      <cache name="org.hibernate.cache.internal.standardquerycache"         maxentrieslocalheap="5" eternal="false" timetoliveseconds="120">         <persistence strategy="localtempswap" />     </cache>      <cache name="org.hibernate.cache.spi.updatetimestampscache"         maxentrieslocalheap="5000" eternal="true">         <persistence strategy="localtempswap" />     </cache> </ehcache> 

pom.xml

<spring.version>4.0.5.release</spring.version> <spring.security.version>3.2.5.release</spring.security.version> <spring.webflow.version>2.4.1.release</spring.webflow.version> <myfaces.version>2.2.7</myfaces.version> <hibernate.version>4.3.6.final</hibernate.version <commons.dbcp.version>1.4</commons.dbcp.version> <mysql.connector.version>5.1.31</mysql.connector.version> 

i'm current working local machine(16gb ram,i7,ssd disk).and want best performance web application.but not have sufficient knowledge , experience job.please give me advice it.(version,driver class,hibernate properties,ehcache properties..etc) in advice..

hi try suggest somethings think can lead better performance:-

1. reduce primary key generation overhead
in processes 'insert-intensive', choice of primary key generation strategy can matter lot. 1 common way generate id's use database sequences, 1 per table

2. use jdbc batch inserts/updates
batch programs, jdbc drivers provide optimization reducing network round-trips named 'jdbc batch inserts/updates' entity manager factory configuration needed active batch inserts/updates:

 <prop key="hibernate.jdbc.batch_size">150</prop>  <prop key="hibernate.order_inserts">true</prop>  <prop key="hibernate.order_updates">true</prop> 

setting jdbc batch size won't work
3. periodically flush , clear hibernate session

long-running sessions should avoided as possible, if reason needed, how contain memory consumption:

entitymanager.flush(); entitymanager.clear(); 

the flush trigger inserts new entities sent database. clear releases new entities session.

4. reduce hibernate dirty-checking overhead
hibernate uses internally mechanism keep track of modified entities called dirty-checking.
hibernate it's keep performance cost of dirty-checking minimum, , dirty-check when needs to, mechanism have cost, more noticeable in tables large number of columns.one way is

@transactional(readonly=true) public void somemethod() {} 

ways avoid dirty checking

5. use second-level , query caches
if data identified being eligible caching,try using second level cache. setup , disadvantages of second level cache

6. search 'bad' querys
bad queries e.g.
full table scans: happen when table being scanned.try projection
full cartesian joins: means full cartesian product of several tables being computed.

7. review table indexes.

application , schema grows, checking indexes become more complex , orm tool cannot automatically define indexes you. review indexes, enable show_sql , check sql statements if attributes in clause have proper indexes. also, review indexes created on foreign keys. in short, not trust orm tool automatically define indexes you.if possible, make indexed columns not-nullable.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -