Bladeren bron

修改 idworker 参数,新增并发测试

hubin 9 jaren geleden
bovenliggende
commit
db23427679

+ 14 - 0
mybatis-plus/pom.xml

@@ -41,6 +41,8 @@
 		<servlet-api.version>2.5</servlet-api.version>
 		<spring.version>4.2.5.RELEASE</spring.version>
 		<mybatis-ehcache.version>1.0.3</mybatis-ehcache.version>
+		<junit.version>4.12</junit.version>
+		<contiperf.version>2.3.4</contiperf.version>
 	</properties>
 
 	<dependencies>
@@ -111,6 +113,18 @@
 			<version>${logback-classic.version}</version>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+		    <groupId>junit</groupId>
+		    <artifactId>junit</artifactId>
+		    <version>${junit.version}</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+		    <groupId>org.databene</groupId>
+		    <artifactId>contiperf</artifactId>
+		    <version>${contiperf.version}</version>
+			<scope>test</scope>
+		</dependency>
 		<!-- test end -->
 	</dependencies>
 

+ 4 - 4
mybatis-plus/src/main/java/com/baomidou/mybatisplus/toolkit/Sequence.java

@@ -30,11 +30,11 @@ import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
  * @date 2016-08-01
  */
 public class Sequence {
-	/* 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动)*/
+	/* 时间起始标记点,作为基准,一般取系统的最近时间(一旦确定不能变动) */
 	private final long twepoch = 1288834974657L;
-	private final long workerIdBits = 10L;/* 机器标识位数 */
-	private final long datacenterIdBits = 10L;
-	private final long maxWorkerId = -1L ^ (-1L << workerIdBits);/* 机器ID最大值 1023 */
+	private final long workerIdBits = 5L;/* 机器标识位数 */
+	private final long datacenterIdBits = 5L;
+	private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
 	private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
 	private final long sequenceBits = 12L;/* 毫秒内自增位 */
 	private final long workerIdShift = sequenceBits;

+ 35 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/ContiPerfTest.java

@@ -0,0 +1,35 @@
+package com.baomidou.mybatisplus.test;
+
+import org.databene.contiperf.PerfTest;
+import org.databene.contiperf.junit.ContiPerfRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import com.baomidou.mybatisplus.toolkit.IdWorker;
+
+/**
+ * <p>
+ * 并发测试
+ * </p>
+ * 
+ * @author hubin
+ * @date 2016-08-18
+ */
+public class ContiPerfTest {
+	
+	@Rule
+	public ContiPerfRule i = new ContiPerfRule();
+
+	/**
+	 * samples: 200000000
+	 * max: 82
+	 * average: 0.0039698
+	 * median: 0
+	 */
+	@Test
+	@PerfTest(invocations = 200000000, threads = 16)
+	public void testIdWorker() throws Exception {
+		IdWorker.getId();
+	}
+
+}