Home Database Mysql Tutorial Mysql Tomcat C3p0系统性能调优个人总结_MySQL

Mysql Tomcat C3p0系统性能调优个人总结_MySQL

Jun 01, 2016 pm 01:01 PM
personal performance system

系统信息

应用逻辑 就是用c3p0 到数据库查询数据并http返回Json数据

 

1 调优前的最初的测试结果 JMeter test result

No.

Type

Original

1000 data bigger

1

500Connection

250 query/S

63q/S
70q/S

2

1000 connections

255q/S

57q/S

65 q/S

这个数据是从程序的log 中打印出的 数据库select语句 中得出的结果(正确与否后面会有讨论)。

2 经过IOD系统打印 SQL query 的执行时间 和 tomcat 每个request 的 响应时间,找出 系统瓶颈 是因为一个 select语句 使用了 in:

SELECT* FROM infoobject_table where category = 'advertisement' and deleteflag=falseand (id in (select info_object_fk from timespan_table where vod_id = ? and deleteflag=false))Order By Rand() Limit

在 原来的小数据库中 数据较少 查询 时间 100ms 左右

在 1000个 video 的数据库中 查询的时间 达到 超过 1S

先注释掉 这个语句 ,想办法用优化的办法实现这个功能。

 

注释掉 这个 select 语句后得到的测试数据(还是计算从程序的log中打印出的 数据库select语句)Jmeter testresult

No.

Type

Original

1000 bigger

1

500Connection

250 query/S

CPU 100%
150q/S

2

1000 connections

255q/S

160q/S

160q/S

现在 的问题 是碰到 tomcat request 160q/S 再怎么调优 增加不了了,tomcat的内存 配置了4G 实际使用了不到 1个G ,CPU 8核心 利用率 只有10%。

 

3 发现前面的统计系统响应 性能有问题,很多时候sql 语句打印出来了,但是并没有执行完成, 因为c3p0 连接数只有15个,都在等待数据库连接,后来改变统计方式。

还有就是打印出 c3p0 的连接池的工作状态

 

private void printDataConnections() {
        ComboPooledDataSource ds = (ComboPooledDataSource) DBConn.getDataSource();
        StringBuffer connectionBuffer = new StringBuffer();
        try {
            connectionBuffer.append("getMaxPoolSize=" + ds.getMaxPoolSize());// 最大连接数
            connectionBuffer.append("getMinPoolSize=" + ds.getMinPoolSize());// 最小连接数
            connectionBuffer.append("getNumBusyConnections=" + ds.getNumBusyConnections());// // 正在使用连接数
            connectionBuffer.append("getNumIdleConnections=" + ds.getNumIdleConnections());// 空闲连接数
            connectionBuffer.append("getNumConnections=" + ds.getNumConnections());//总连接数
            logger.info("  connectionBuffer=" + connectionBuffer.toString()); 
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }
Copy after login


后来进行mysql(默认100最大链接), tomcat(连接数default)tomcat 内存配置, c3p0(最大15个链接) 链接池优化。

Mysql: 在system/programdata/mysql/my.ini中配置

max_connections=1000

Tomcat: 配置连接数

<Connector port="8080"protocol="HTTP/1.1"       
                                  minSpareThreads="25"
                                  maxSpareThreads="75"
         enableLookups="false"
                                  disableUploadTimeout="true"
                                  connectionTimeout="20000"
         acceptCount="200" 
                                  maxThreads="800"
                                  minThreads="600"
                                  maxProcessors="1000"
                                  minProcessors="1000"
         useURIValidationHack="false"
    
              redirectPort="8443"
/>
Copy after login


配置 tomcat 运行jvm 配置

set JAVA_OPTS=-server -Xms4400M-Xmx4400M -Xss512k -XX:+AggressiveOpts -XX:+UseBiasedLocking -XX:PermSize=128M-XX:MaxPermSize=256M -XX:+DisableExplicitGC -XX:MaxTenuringThreshold=31-XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+UseCMSCompactAtFullCollection-XX:LargePageSizeInBytes=128m -XX:+UseFastAccessorMethods -XX:+UseCMSInitiatingOccupancyOnly-Djava.awt.headless=true

应用 c3p0 连接池配置:

<bean id="dataSource" 
       class="com.mchange.v2.c3p0.ComboPooledDataSource"destroy-method="close"> 
        <propertyname="driverClass" value="com.mysql.jdbc.Driver" /> 
        <property name="jdbcUrl"value="jdbc:mysql://192.168.4.112:3306/iod1000?useUnicode=true&characterEncoding=utf-8"/> 
      <propertyname="checkoutTimeout" value="60000"/>
     <propertyname="idleConnectionTestPeriod" value="30"/>
     <propertyname="initialPoolSize" value="50"/>
     <property name="maxPoolSize"value="800"/>
     <property name="minPoolSize"value="50"/>
     <propertyname="maxStatements" value="100"/>
    <propertyname="properties"> 
        <props>          
            <propkey="preferredTestQuery">SELECT 1</prop>   
            <propkey="c3p0.maxIdleTime">25000</prop>   
            <propkey="c3p0.testConnectionOnCheckout">true</prop> 
            <propkey="user">root</prop>   
            <prop key="password">iptv4Um8</prop> 
        </props> 
      </property> 
</bean>
Copy after login


 

查询配置了mysql 最大连接数 1000, 配置 c3p0 连接池 800 配置 tomcat 链接 800 测试结果:

CPU 8Core 12% usage

Memmory900M/2.4G 120q/S

这个时候碰到的问题就是 cpu 和 内存 都没有达到上限,但是查询的 性能却提升不上去了。

 

5 试用jconsole 查看tomcat 中的 线程状态,好多线程都是 blocked on java.util.logging.console 原来是线程一直在等待写日志被block住了。

把写log的语句 全部注释掉。OK 系统终于飞起来了。

现在 能达到 250q/S。

 

需要检查的地方:

CPU

内存

mysql最大连接数

tomcat 连接数配置

tomcat JVM 配置 重要的是内存大小

数据库连接池配置:

程序内部的瓶颈。

 

 

 

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time Jul 30, 2024 pm 02:17 PM

Huawei's Qiankun ADS3.0 intelligent driving system will be launched in August and will be launched on Xiangjie S9 for the first time

Comparing the performance of Win11 and Win10 systems, which one is better? Comparing the performance of Win11 and Win10 systems, which one is better? Mar 27, 2024 pm 05:09 PM

Comparing the performance of Win11 and Win10 systems, which one is better?

Windows 10 vs. Windows 11 performance comparison: Which one is better? Windows 10 vs. Windows 11 performance comparison: Which one is better? Mar 28, 2024 am 09:00 AM

Windows 10 vs. Windows 11 performance comparison: Which one is better?

Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use Jun 02, 2024 pm 02:58 PM

Always new! Huawei Mate60 series upgrades to HarmonyOS 4.2: AI cloud enhancement, Xiaoyi Dialect is so easy to use

The local running performance of the Embedding service exceeds that of OpenAI Text-Embedding-Ada-002, which is so convenient! The local running performance of the Embedding service exceeds that of OpenAI Text-Embedding-Ada-002, which is so convenient! Apr 15, 2024 am 09:01 AM

The local running performance of the Embedding service exceeds that of OpenAI Text-Embedding-Ada-002, which is so convenient!

Performance comparison of different Java frameworks Performance comparison of different Java frameworks Jun 05, 2024 pm 07:14 PM

Performance comparison of different Java frameworks

What impact do C++ functions have on program performance? What impact do C++ functions have on program performance? Apr 12, 2024 am 09:39 AM

What impact do C++ functions have on program performance?

PHP array key value flipping: Comparative performance analysis of different methods PHP array key value flipping: Comparative performance analysis of different methods May 03, 2024 pm 09:03 PM

PHP array key value flipping: Comparative performance analysis of different methods

See all articles