# Test100 **Repository Path**: licslan/Test100 ## Basic Information - **Project Name**: Test100 - **Description**: 测试多线程(线程池)与单线程写数据到MySQL效率对比 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2021-02-21 - **Last Updated**: 2021-12-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Getting Started ### Reference Documentation Do test for Multithreading and Single thread: * [Official Apache Maven documentation](https://maven.apache.org/guides/index.html) * [Spring Boot Maven Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.4.3/maven-plugin/reference/html/) * [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.4.3/maven-plugin/reference/html/#build-image) * [Spring Web](https://docs.spring.io/spring-boot/docs/2.4.3/reference/htmlsingle/#boot-features-developing-web-applications) * [MyBatis Framework](https://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/) ### Guides The following guides illustrate how to use some features concretely: * [Accessing data with MySQL](https://spring.io/guides/gs/accessing-data-mysql/) * [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/) * [Serving Web Content with Spring MVC](https://spring.io/guides/gs/serving-web-content/) * [Building REST services with Spring](https://spring.io/guides/tutorials/bookmarks/) * [MyBatis Quick Start](https://github.com/mybatis/spring-boot-starter/wiki/Quick-Start) * [Spring Data Elasticsearch (Access+Driver)](https://docs.spring.io/spring-boot/docs/2.4.3/reference/htmlsingle/#boot-features-elasticsearch) * https://www.cnblogs.com/chuijingjing/p/13527527.html * https://www.cnblogs.com/ywbmaster/p/13026742.html ### Test result blow * we use 1000 as init data and insert those data to MySQL * we use 5000 as second time and insert those data to MySQL * we use 50000 as Third time and insert those data to MySQL * we use 500000 as fourth time and insert those data to MySQL * we use 1000000 as fifth time and insert those data to MySQL * 实验结果 MySQL < 1c 2g * * 相同条件下面 重启服务 写入数据 重建表 再写入数据对比 * 1000条 首次 测试1000写入 * 实验结果如下: * 单线程: * 写入1000条 * 单线程统计用时:1746 毫秒 * 多线程: * 每次写入数据库多少[ 1000 ]条 * 多线程统计用时:1136 毫秒 * ==================================== * 5000条 第二次 测试5000写入 * 单线程: * 写入5000条 * 单线程统计用时:1344 毫秒 * * 多线程: * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 多线程统计用时:1809 毫秒 * ==================================== * 50000条 第三次 测试5万写入 * 单线程: * 写入50000条 * 单线程统计用时:2857 毫秒 * 多线程: * 每次写入数据库多少[ 2500 ]条 * * 每次写入数据库多少[ 2500 ]条 * 多线程统计用时:2360 毫秒 * 上面已经有了约500毫秒差距 多线程快 500毫秒 * ==================================== * 500000条 第四次 测试50万条数据写入 * 单线程: * 写入500000条 * 单线程统计用时:23786 毫秒 约 24秒钟 * 多线程: * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * 多线程统计用时:9021 毫秒 约 9 秒 比上面的24秒快15秒了 !!! * 其实可以尝试提高每次写入的数据batchSize 当前2500 但是 mybatis批量写入一次好像是有限制的 忘记了多少 可以查一下 * 下面调整为batchSize = 10000 * 每次写入数据库多少[ 10000 ]条 * * 每次写入数据库多少[ 10000 ]条 * 多线程统计用时:9425 毫秒 * 下面调整为batchSize = 5000 * 每次写入数据库多少[ 5000 ]条 * * 每次写入数据库多少[ 5000 ]条 * 多线程统计用时:9620 毫秒 * 对比发现 2500 5000 10000 时 时间差不多了 * ==================================== * 1000000条 第五次 测试100万条数据写入 此时batchSize恢复为 2500 * 单线程: * 写入1000000条 * 单线程统计用时:44271 毫秒 约44秒 * 多线程: * 每次写入数据库多少[ 2500 ]条 * 每次写入数据库多少[ 2500 ]条 * * 每次写入数据库多少[ 2500 ]条 * 多线程统计用时:15062 毫秒 约 15秒 ### How we start? * Install JDK8+ Maven3.2+ * Follow the spring.io to build a spring boot project * Add dependence file in pom.xml file * Connect to MySQL first and then read and wirte data to database * Then write code about thread pool # Test100 #### 介绍 测试多线程(线程池)与单线程写数据到MySQL效率对比 #### 软件架构 软件架构说明 #### 安装教程 1. xxxx 2. xxxx 3. xxxx #### 使用说明 1. xxxx 2. xxxx 3. xxxx #### 参与贡献 1. Fork 本仓库 2. 新建 Feat_xxx 分支 3. 提交代码 4. 新建 Pull Request #### 特技 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)