当前位置: 首页 > news >正文

丰富网站内容台州网站制作网站建设

丰富网站内容,台州网站制作网站建设,网站备案 深圳,网站建设方案范例文章目录 配置 RedisTemplate验证blocking操作在独立连接上进行验证单tcp连接的多路复用 redis multiplexing机制类似http2#xff0c;在存在并发请求时能减少大量通讯延迟#xff0c;但不支持blocking相关的操作#xff0c;如BLPOP 配置 RedisTemplate RedisTemplate自动… 文章目录 配置 RedisTemplate验证blocking操作在独立连接上进行验证单tcp连接的多路复用 redis multiplexing机制类似http2在存在并发请求时能减少大量通讯延迟但不支持blocking相关的操作如BLPOP 配置 RedisTemplate RedisTemplate自动根据操作类型选择是在单连接上进行多路复用还是申请新的连接/等待空闲连接 Configuration public class RedisTemplateConfig {Beanpublic LettuceConnectionFactory lettuceConnectionFactory(Value(${redis.cluster}) String address,Value(${redis.password}) String password) {// 配置连接池管理var poolConfig new GenericObjectPoolConfigStatefulRedisClusterConnectionString, String();poolConfig.setMaxTotal(20);poolConfig.setMaxIdle(20);poolConfig.setMinIdle(2);poolConfig.setTestWhileIdle(true);poolConfig.setMinEvictableIdleDuration(Duration.ofMillis(60000));poolConfig.setTimeBetweenEvictionRuns(Duration.ofMillis(30000));poolConfig.setNumTestsPerEvictionRun(-1);// 配置客户端行为var clientConfig LettucePoolingClientConfiguration.builder().clientOptions(ClusterClientOptions.builder().autoReconnect(true).pingBeforeActivateConnection(true).socketOptions(SocketOptions.builder().connectTimeout(Duration.ofSeconds(3)).build()).timeoutOptions(TimeoutOptions.builder().fixedTimeout(Duration.ofSeconds(3)).build()).topologyRefreshOptions(ClusterTopologyRefreshOptions.builder().enableAdaptiveRefreshTrigger(RefreshTrigger.MOVED_REDIRECT,RefreshTrigger.PERSISTENT_RECONNECTS).adaptiveRefreshTriggersTimeout(Duration.ofSeconds(30)).build()).build()).poolConfig(poolConfig).build();// 配置集群连接信息var redisConfig new RedisClusterConfiguration();redisConfig.setMaxRedirects(5);redisConfig.setPassword(password);String[] serverArray address.split(,||;|);// 获取服务器数组SetRedisNode nodes new HashSet();for (String ipPort : serverArray) {nodes.add(RedisNode.fromString(ipPort));}redisConfig.setClusterNodes(nodes);return new LettuceConnectionFactory(redisConfig, clientConfig);}Beanpublic StringRedisTemplate redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {return new StringRedisTemplate(lettuceConnectionFactory);} }验证blocking操作在独立连接上进行 实现blocking LPOP操作的方法在opsForList()里 并发100压测期间查看客户端本地的tcp连接可以看到和每个redis节点都建立了大量连接 证明RedisTemplate没有选择让不同并发线程共用同一个StatefulConnection Testpublic void blpop() throws Exception {long start System.currentTimeMillis();AtomicLong err new AtomicLong();int maxThreads 100;Semaphore semaphore new Semaphore(maxThreads);for (int i 0; i maxThreads; i) {final int threadnum i 1;semaphore.acquire(1);new Thread(new Runnable() {Overridepublic void run() {try {template.opsForList().leftPop(test threadnum, 2, TimeUnit.SECONDS);} catch (Exception ex) {log.error(leftPop, ex);err.addAndGet(1L);} finally {semaphore.release(1);}}}).start();}semaphore.acquire(maxThreads);long end System.currentTimeMillis();log.info(耗时{}ms, 错误{}, end - start, err.get());}验证单tcp连接的多路复用 发起100个线程每个线程连续进行1000次读写操作 执行期间查看客户端本地的tcp连接可以看到只建立了一个和redis节点的连接 每个线程的指令并发地在同一个tcp连接上发出和响应一次请求响应实际相当于http2的一路stream Slf4j EnableAutoConfiguration(exclude { RedisAutoConfiguration.class }) SpringBootTest(classes { RedisTemplateConfig.class }) public class RedisTemplateTest {AutowiredStringRedisTemplate template;Testpublic void getSet() throws Exception {long start System.currentTimeMillis();int maxThreads 100;long maxMessagess 1000;AtomicLong err new AtomicLong();AtomicLong num new AtomicLong();Semaphore semaphore new Semaphore(maxThreads);for (int i 0; i maxThreads; i) {final int threadnum i 1;semaphore.acquire(1);new Thread(new Runnable() {Overridepublic void run() {int j 0;try {for (; j maxMessagess; j) {String key thread threadnum test j;String value test j;template.opsForValue().set(key, value, 1, TimeUnit.SECONDS);assertEquals(value, template.opsForValue().get(key));}} finally {num.addAndGet(j);semaphore.release(1);}}}).start();}semaphore.acquire(maxThreads);long end System.currentTimeMillis();double rate 1000d * num.get() / (end - start);log.info(每秒发送并读取消息{}; 耗时{}ms, 累计发送{}, rate, end - start, num.get());}RedisTemplate屏蔽了哪些并发命令可以共用连接的决策难点所以不要自行使用Lettuce客户端获取连接或从连接池申请连接。
http://www.zqtcl.cn/news/635556/

相关文章:

  • 微小店网站建设价格建设网站设备预算
  • 电子商城网站开发公司泰州网络营销
  • 网站建设公司利润分配一些常用的网站
  • 鄂尔多斯做网站的公司北京企业网站设计报价
  • 南宁关键词网站排名wordpress付免签插件
  • 龙岩网站定制电子政务与网站建设方面
  • 东莞网站制作十强英语培训机构网站建设策划书
  • 住房和城乡建设部网站加装电梯苏州外发加工网
  • 企业网站管理系统带授权广州seo报价
  • 建设门户网站的意义旅游电商网站建设方案模板
  • 网站做动态图片不显示某购物网站开发项目
  • 大淘客网站logo怎么做紫鸟超级浏览器手机版
  • 专做公司网站 大庆wordpress编辑器百度云
  • 企业手机网站模板下载网站建设实训 考核要求
  • 企业网站建设的ppt4414站长平台
  • 物流网站制作怎么做pc网站开发
  • 合肥做网站可以吗网站程序 seo
  • 网站备案 动态ip网站多域名
  • 网站加速免费电子商务网站建设的认识
  • 做职业资格考试的网站有哪些网页游戏排行榜2024前十名
  • 网站设计方案怎么写wordpress仿站软件
  • 汕头建站模板系统北京有哪些电商平台公司
  • 深圳网站建设zhaoseo小包工头接活的平台
  • 电商平面设计前景如何seo推广什么意思
  • 网站解析不了wordpress 密码失败
  • 临沂企业建站系统模板扮家家室内设计
  • 做简单网站用什么软件网站开发国外研究现状
  • 江苏seo推广网站建设湖南软件定制开发
  • 台州商务网站手机端seo
  • 网站的切换语言都是怎么做的有哪些开发网站公司