Home  >  Article  >  Database  >  多种方式测试redis入库性能

多种方式测试redis入库性能

WBOY
WBOYOriginal
2016-06-07 16:31:281304browse

? ? Transaction Pipeline 耗时(s) 测试一: N N 311 测试二: N Y 10 测试三: Y Y 7 测试四: Y N 10 ? 结论:Pipeline + Transaction方式是几种插入方式中性能最好的。虽然有点意外,但测试多次仍然是这个结论。 ? 测试代码如下: ? import org.apache.

?

? Transaction Pipeline 耗时(s)
测试一: N N 311
测试二: N Y 10
测试三: Y Y 7
测试四: Y N 10

?

结论:Pipeline + Transaction方式是几种插入方式中性能最好的。虽然有点意外,但测试多次仍然是这个结论。

?

测试代码如下:

?

import org.apache.commons.lang.RandomStringUtils;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Transaction;
public class RedisTransactionTest {
	private static String host = "xx.xx.xx.xx";
	private static JedisPool pool = new JedisPool(new JedisPoolConfig(), host);
	private long rowCount = 1000000; // 100万
	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		new RedisTransactionTest().noTransactionNoPipeline();
		System.out.println("noTransactionNoPipeline use " + (System.currentTimeMillis() - start) / 1000);
		pool = new JedisPool(new JedisPoolConfig(), host);
		start = System.currentTimeMillis();
		new RedisTransactionTest().pipelineWithoutTransaction();
		System.out.println("pipelineWithoutTransaction use " + (System.currentTimeMillis() - start) / 1000);
		pool = new JedisPool(new JedisPoolConfig(), host);
		start = System.currentTimeMillis();
		new RedisTransactionTest().pipelineWithTransaction();
		System.out.println("pipelineWithTransaction use " + (System.currentTimeMillis() - start) / 1000);
		pool = new JedisPool(new JedisPoolConfig(), host);
		start = System.currentTimeMillis();
		new RedisTransactionTest().transactionNoPipeline();
		System.out.println("transactionNoPipeline use " + (System.currentTimeMillis() - start) / 1000);
	}
	public void pipelineWithoutTransaction() {
		Jedis jedis = pool.getResource();
		try {
			Pipeline p = jedis.pipelined();
			for (int i = 0; i 
  <p>?--end</p>
  <p>?</p>
  <p>?</p>

               <br> <br>
                 已有   <strong>0</strong> 人发表留言,猛击->>  <strong>这里</strong> <br> <br>
ITeye推荐
 <br>
 
  • —软件人才免语言低担保 赴美带薪读研!—



多种方式测试redis入库性能

Statement:
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