The optimization technology of database mainstream:
Read optimization: Indexed, but not too much. Too much can degrade efficiency, and the type cannot be null;
Insert, Mass read: Bulk operations, bulk inserts than normal insertion performance is dozens of times times worse.
It's too big: a table, a read-write separation.
There is also a connection pool:
Create a connection pool to maintain a certain number of connections. This allows a database connection to be used directly if there is an idle connection, reducing the time it took to create a database connection.
China's current mainstream connection pool technology is druid, what other Proxool, now very few people use, after all, technology in progress. It also provides good monitoring.
Use: Download Alibaba's jar pack.
Configure DataSource:
<!--configuration Data source--> <bean id= "DataSource" class= "Com.alibaba.druid.pool.DruidDataSource" init-method= "Init"
destroy-method= "Close" > <property name= "driverclassname" value= "Com.mysql.jdbc.Driver" ></property> <property name= "url" value= "jdbc:mysql://localhost/test" ></property> <property name= "username" value = "root" ></property> <property name= "password" value= "" ></property> <!--Configure Connection number--> < Property Name= "InitialSize" value= "1"/> <property name= "Minidle" value= "1"/> <property name= "MaxActive" value=/> <!--Configure the maximum wait time for a single connection--> <property name= "maxwait" value= "60000"/> <!-- 10 minutes Interval Check if all connections need to close or create--> <property name= "Timebetweenevictionrunsmillis" value= "60000"/> <!-- Configure minimum survival time: 5 min--> <property name= "Minevictableidletimemillis" value= "300000"/> <property name= " Validationquery "value=" select ' X ' "/> <property name=" Testwhileidle "value=" true "/> <property name= "Testonborrow" value= "false"/> <property name= "Testonreturn" value= "false"/> <!--open Pscache, and specify the size of the Pscache on each connection--> <property name= "poolpreparedstatements" value= "true"/> <property name= " Maxpoolpreparedstatementperconnectionsize "value="/> <!--configuration Monitors statistical interception filters, monitor interface SQL statistics--> <property Name= "Filters" value= "stat"/> </bean>
This way, the connection pool is already created. Now the use of technology is really not difficult, the most important thing is to have the consciousness to learn, to use.
Monitoring configuration: Use the filter principle.
<filter>
<filter-name>DruidWebStatFilter</filter-name>
<filter-class> com.alibaba.druid.support.http.webstatfilter</filter-class>
<init-param>
<param-name >exclusions</param-name>
<param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*</ param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name> druidwebstatfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping >
Configure access paths.
<servlet>
<servlet-name>DruidView</servlet-name>
<servlet-class> com.alibaba.druid.support.http.statviewservlet</servlet-class>
</servlet>
< servlet-mapping>
<servlet-name>DruidView</servlet-name>
<url-pattern>/druid/*< /url-pattern>
</servlet-mapping>
This is the basic use.