概述
1 首先在 本地搭建一个虚拟机,安装mysql
2 对mysql 单表数据量测试 这里使用spring boot 配合durid 和 mybatis 来搭建 ,下面会详细介绍
这里先 贴上 pom,因为前段时间 在对比 postgre,mongodb 等数据库,pom里面还有一些其他的引用,将就看吧。
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.zqm
eureka
1.0-SNAPSHOT
war
Demo project for Spring Boot
org.springframework.boot
spring-boot-starter-parent
1.4.3.RELEASE
UTF-8
UTF-8
1.8
com.datastax.cassandra
cassandra-driver-core
3.0.0
org.postgresql
postgresql
9.4.1212
org.springframework.boot
spring-boot-starter-web
org.springframework.boot
spring-boot-starter-thymeleaf
org.springframework.cloud
spring-cloud-starter-eureka-server
org.springframework.boot
spring-boot-devtools
true
org.springframework.boot
spring-boot-starter-jdbc
mysql
mysql-connector-java
runtime
org.springframework.boot
spring-boot-configuration-processor
true
org.springframework.boot
spring-boot-starter-data-mongodb
com.fasterxml.jackson.core
jackson-core
com.fasterxml.jackson.core
jackson-databind
com.fasterxml.jackson.datatype
jackson-datatype-joda
com.fasterxml.jackson.module
jackson-module-parameter-names
com.github.pagehelper
pagehelper-spring-boot-starter
1.1.2
org.springframework.boot
spring-boot-starter-data-jpa
org.springframework.boot
spring-boot-starter-data-redis
com.alibaba
druid-spring-boot-starter
1.1.6
com.alibaba
druid-spring-boot-starter
1.1.6
junit
junit
test
org.springframework
spring-test
4.3.12.RELEASE
test
org.springframework.boot
spring-boot-test
1.5.8.RELEASE
test
org.mybatis
mybatis
3.4.1
org.springframework.cloud
spring-cloud-dependencies
Camden.SR4
pom
import
org.springframework.boot
spring-boot-maven-plugin
application.yml 的配置
#server:
# port: 8761 # 指定该Eureka实例的端口
#eureka:
# client:
# registerWithEureka: false
# fetchRegistry: false
# serviceUrl:
# defaultZone: http://localhost:8761/eureka/
#
## 参考文档:http://projects.spring.io/spring-cloud/docs/1.0.3/spring-cloud.html#_standalone_mode
## 参考文档:http://my.oschina.net/buwei/blog/618756
server:
port: 8080
tomcat:
max-threads: 5000
min-spare-threads: 5000
mybatis:
mapper-locations: classpath:mapping/*.xml
type-aliases-package: com.zqm.eureka.mysql.beans
#pagehelper分页插件
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
spring:
data:
cassandra:
keyspace-name: yiibai_ks
contact-points: 127.0.0.1
port: 9042
# mongodb:
# host: 127.0.0.1
# port: 30000
# database: zqm
# custom:
# connections-per-host: 5000
# min-connections-per-host: 500
# uri: mongodb://localhost:27017/test
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML5
encoding: UTF-8
content-type: text/html
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
name: druid
druid:
min-idle: 1000
max-active: 6000
max-wait: 6000
url: jdbc:mysql://10.24.18.111:3306/test?useSSL=false
druid 的配置
packagecom.zqm.eureka;importcom.alibaba.druid.support.http.StatViewServlet;importcom.alibaba.druid.support.http.WebStatFilter;importorg.springframework.boot.autoconfigure.condition.ConditionalOnClass;importorg.springframework.boot.autoconfigure.condition.ConditionalOnProperty;importorg.springframework.boot.autoconfigure.jdbc.DataSourceProperties;importorg.springframework.boot.context.properties.ConfigurationProperties;importorg.springframework.boot.jdbc.DatabaseDriver;importorg.springframework.boot.web.servlet.FilterRegistrationBean;importorg.springframework.boot.web.servlet.ServletRegistrationBean;importorg.springframework.context.annotation.Bean;importorg.springframework.context.annotation.Configuration;importjavax.sql.DataSource;importjava.io.Serializable;importjava.util.Map;@Configuration
@ConditionalOnClass(com.alibaba.druid.pool.DruidDataSource.class)
@ConditionalOnProperty(name= "spring.datasource.type", havingValue = "com.alibaba.druid.pool.DruidDataSource", matchIfMissing = true)public class DruidDataSourceConfiguration implementsSerializable{
@SuppressWarnings("unchecked")protected T createDataSource(DataSourceProperties properties,
Class extends DataSource>type) {return(T) properties.initializeDataSourceBuilder().type(type).build();
}@Bean(name= "dataSource")
@ConfigurationProperties("spring.datasource.druid")publiccom.alibaba.druid.pool.DruidDataSource dataSource(DataSourceProperties properties) {
com.alibaba.druid.pool.DruidDataSource dataSource=createDataSource(
properties, com.alibaba.druid.pool.DruidDataSource.class);
DatabaseDriver databaseDriver=DatabaseDriver.fromJdbcUrl(properties.determineUrl());
String validationQuery=databaseDriver.getValidationQuery();if (validationQuery != null) {
dataSource.setTestOnBorrow(true);
dataSource.setValidationQuery(validationQuery);
}returndataSource;
}/*** 注册一个StatViewServlet*/@BeanpublicServletRegistrationBean druidStatViewServlet(){//org.springframework.boot.context.embedded.ServletRegistrationBean提供类的进行注册.
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");//添加初始化参数:initParams//IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的话提示:Sorry, you are not permitted to view this page.
servletRegistrationBean.addInitParameter("deny","127.0.0.1");//登录查看信息的账号密码.
servletRegistrationBean.addInitParameter("loginUsername","root");
servletRegistrationBean.addInitParameter("loginPassword","password");//是否能够重置数据.
servletRegistrationBean.addInitParameter("resetEnable","false");//禁用HTML页面上的“Reset All”功能
returnservletRegistrationBean;
}/*** 注册一个:filterRegistrationBean*/@BeanpublicFilterRegistrationBean druidStatFilter(){
FilterRegistrationBean filterRegistrationBean= new FilterRegistrationBean(newWebStatFilter());
filterRegistrationBean.setName("druidWebStatFilter");//添加过滤规则.
filterRegistrationBean.addUrlPatterns("/*");//添加忽略的格式信息.
filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");returnfilterRegistrationBean;
}
}
创建studengMapper.xml
INSERT INTO student(NAME,AGE,PHONE,ADDRESS) VALUES(#{name},#{age},#{phone},#{address});
StudentMapper.java
packagecom.zqm.eureka.mysql.mapper;importcom.zqm.eureka.mysql.beans.Student;importorg.apache.ibatis.annotations.Mapper;importorg.springframework.transaction.annotation.Transactional;
@Mapperpublic interfaceStudentMapper {
@Transactionalpublic intaddStudent(Student student);
}
服务端StudentService.java 编写
packagecom.zqm.eureka.mysql.service;importcom.zqm.eureka.mysql.beans.Student;importcom.zqm.eureka.mysql.mapper.StudentMapper;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.stereotype.Service;
@Servicepublic classStudentService {
@Autowired
StudentMapper studentMapper;public intaddStudent(Student student) {returnstudentMapper.addStudent(student);
}
}
最后我们来验证一下
packagecom.zqm.eureka.mysql.web;importcom.zqm.eureka.mysql.beans.Student;importcom.zqm.eureka.mysql.mapper.StudentMapper;importorg.junit.Test;importorg.junit.runner.RunWith;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.boot.test.context.SpringBootTest;importorg.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTestpublic classStudentTest {
@AutowiredprivateStudentMapper studentMapper;
@Testpublic voidtest(){
Student student= newStudent();
student.setAddress("q");
student.setAge(11);
student.setName("zz");
student.setPhone("123456789");
studentMapper.addStudent(student);
}
}
然后我们用jmeter 来压入十万条数据看看 占用多少空间,当然这里只能相对来分析。
packagecom.zqm.eureka.mysql.web;importcom.zqm.eureka.mysql.beans.Student;importcom.zqm.eureka.mysql.service.StudentService;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.web.bind.annotation.PathVariable;importorg.springframework.web.bind.annotation.RequestMapping;importorg.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("student")public classStudentController {
@Autowired
StudentService studentService;
@RequestMapping("add/{address}/{phone}/{age}/{name}")public String addStudent(@PathVariable(value ="address") String address,
@PathVariable(value="phone") String phone,
@PathVariable(value="age") intage,
@PathVariable(value="name") String name){
Student student= newStudent();
student.setAddress(address);
student.setAge(age);
student.setName(name);
student.setPhone(phone);int i = 0;try{
i=studentService.addStudent(student);if(i!=1){return "失败";
}return "成功";
}catch(Exception e){return "失败"+e.getMessage();
}
}
}
执行一下看看结果 10w 加的数据 myd 和myi 大概 在 4.3M 左右
最后
以上就是伶俐戒指为你收集整理的mysql5.0 测试_spring boot 整合mybatis,druid 测量 Mysql 5.0+ 数据量测试的全部内容,希望文章能够帮你解决mysql5.0 测试_spring boot 整合mybatis,druid 测量 Mysql 5.0+ 数据量测试所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复