发表于: 2017-10-30 23:59:19

5 723


今天完成的事:

1.完成压测

无负载均衡 配置mamcache 20线程 循环25次 并发 测试服务器

无负载均衡,配置mamcache 10线程,1循环,并发 测试服务器

配置nginx(本地)负载均衡(本地tomcat,远程resin),配置mamcache,100线程 100次循环 。权重均为5


综合以上发现负载均衡并使用memcache效率最高。


2.了解redis相关概念,并在Java中配置使用

首先redis与memcache一样是内存类型数据库,响应速度特别快,都是为了缓解数据库压力而服务。不同的是memcache仅支持键值对存储,而redis支持字符串,键值对,集合等类型。在性能上redis能胜一筹。


首先是pom添加驱动依赖

<dependency>
 <groupId>redis.clients</groupId>
 <artifactId>jedis</artifactId>
 <version>2.8.0</version>
</dependency>


其次在Spring中配置bean

<bean class="redis.clients.jedis.JedisPool">
   <constructor-arg index="0" ref="JedisPoolConfig"/>
   <constructor-arg index="1" value="127.0.0.1"/>
</bean>

<bean id="JedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
   <property name="maxTotal" value="300"/>
   <property name="maxIdle" value="100"/>
   <property name="maxWaitMillis" value="1000"/>
   <property name="testOnBorrow" value="true"/>
</bean>

第一个bean构造函数注入的第一个参数是JedisPoolConfig,第二个是redis运行地址。

要讲一下的是JedisPool有多个重载的构造方法,可自行查看。


其次使用如下:

@Autowired
private JedisPool jedisPool;


public ArrayList getOutStandingStudents() throws Exception {
byte[] bytes = jedisPool.getResource().get("OutstandingStudents".getBytes());
   Jedis jedis = jedisPool.getResource();
   
   if (bytes!=null) {
System.out.println("hehee");
       list = (ArrayList) Util.unserialize(bytes);
       jedisPool.returnResource(jedis);
       return Util.chooseOutstandingStudents(list);
   }

else {
list = studentDao.getOutStandingStudents();
       jedis.set("OutstandingStudents".getBytes(),Util.serialize(list));
       jedisPool.returnResource(jedis);
       return Util.chooseOutstandingStudents(list);
   }
}


明天计划的事情:

redis使用出了一点问题,争取做完提交任务6


遇到的困难:

redis压测,发现压测到300个请求就直接报错了,如下:

redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

at redis.clients.util.Pool.getResource(Pool.java:50)

at redis.clients.jedis.JedisPool.getResource(JedisPool.java:99)

网上找了很久都无法解决,已经明确的是因为没有连接可用而导致的。


还有一个就是说tomcat启动不了也不报错,最后发现是因为自己在方法外调用了方法赋值造成了。

收获:

redis使用经验,负载均衡配置


返回列表 返回列表
评论

    分享到