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

专业企业网站建设多少钱服务上海 教育网站建设

专业企业网站建设多少钱服务,上海 教育网站建设,石家庄企业招聘信息网,关键词查询网站的工具之前在 NebulaGraph学习笔记-自定义SessionPool 这篇文章中实现了自定义的SessionPool,后续在使用中发现经常查询的都是用的同一个Session,以至于某一个节点的负载压力很大。于是看了一下获取Session的方法,发现是顺序遍历,后续可…
之前在 NebulaGraph学习笔记-自定义SessionPool 这篇文章中实现了自定义的SessionPool,后续在使用中发现经常查询的都是用的同一个Session,以至于某一个节点的负载压力很大。于是看了一下获取Session的方法,发现是顺序遍历,后续可以调整遍历方式来改变。
  • 依赖包还是跟之前的一致
<!-- Client依赖包 -->
<dependency><groupId>com.vesoft</groupId><artifactId>client</artifactId><version>3.8.4</version>
</dependency>
  • SessionPool会在构造函数中进行初始化
/*** init the SessionPool* this function is moved into SessionPool's constructor, no need to call it manually.*/
@Deprecated
public boolean init() {if (hasInit.get()) {return true;}while (sessionList.size() < minSessionSize) {try {createSessionObject(SessionState.IDLE);idleSessionSize.incrementAndGet();} catch (Exception e) {log.error("SessionPool init failed. ");throw new RuntimeException("create session failed.", e);}}healthCheckSchedule.scheduleAtFixedRate(this::checkSession, 0, healthCheckTime,TimeUnit.SECONDS);sessionQueueMaintainSchedule.scheduleAtFixedRate(this::updateSessionQueue, 0, cleanTime,TimeUnit.SECONDS);hasInit.compareAndSet(false, true);return true;
}/*** create a {@link NebulaSession} with specified state** @param state {@link SessionState}* @return NebulaSession*/
private NebulaSession createSessionObject(SessionState state)throws ClientServerIncompatibleException, AuthFailedException,IOErrorException, BindSpaceFailedException {SyncConnection connection = new SyncConnection();int tryConnect = sessionPoolConfig.getGraphAddressList().size();// reconnect with all available addresswhile (tryConnect-- > 0) {try {if (sessionPoolConfig.isEnableSsl()) {connection.open(getAddress(), sessionPoolConfig.getTimeout(),sessionPoolConfig.getSslParam(),sessionPoolConfig.isUseHttp2(),sessionPoolConfig.getCustomHeaders());} else {connection.open(getAddress(), sessionPoolConfig.getTimeout(),sessionPoolConfig.isUseHttp2(),sessionPoolConfig.getCustomHeaders());}break;} catch (Exception e) {if (tryConnect == 0 || !reconnect) {throw e;} else {log.warn("connect failed, " + e.getMessage());}}}AuthResult authResult;try {authResult = connection.authenticate(sessionPoolConfig.getUsername(),sessionPoolConfig.getPassword());} catch (AuthFailedException e) {log.error(e.getMessage());if (e.getMessage().toLowerCase().contains("user not exist")|| e.getMessage().toLowerCase().contains("invalid password")) {// close the session poolclose();} else {// just close the connectionconnection.close();}throw e;}NebulaSession nebulaSession = new NebulaSession(connection, authResult.getSessionId(),authResult.getTimezoneOffset(), state);ResultSet result = null;try {result = nebulaSession.execute(useSpace);} catch (IOErrorException e) {log.error("binding space failed,", e);nebulaSession.release();throw new BindSpaceFailedException("binding space failed:" + e.getMessage());}if (!result.isSucceeded()) {nebulaSession.release();throw new BindSpaceFailedException(result.getErrorMessage());}sessionList.add(nebulaSession);return nebulaSession;
}public HostAddress getAddress() {List<HostAddress> addresses = sessionPoolConfig.getGraphAddressList();int newPos = (pos.getAndIncrement()) % addresses.size();HostAddress hostAddress = addresses.get(newPos);log.info("ng address {} {} {} {}", pos.get(), newPos, hostAddress.getHost(), hostAddress.getPort());return hostAddress;
}
  • getSession用于为每次执行查询提供Session,可以看出每次都是从sessionList中顺序取出nebulaSession
/*** return an idle session*/
private synchronized NebulaSession getSession() throws ClientServerIncompatibleException,AuthFailedException, IOErrorException, BindSpaceFailedException {int retry = sessionPoolConfig.getRetryConnectTimes();while (retry-- >= 0) {// if there are idle sessions, get session from queueif (idleSessionSize.get() > 0) {for (NebulaSession nebulaSession : sessionList) {if (nebulaSession.isIdleAndSetUsed()) {int currentIdleSessionSize = idleSessionSize.decrementAndGet();log.info("ng session {} {}", currentIdleSessionSize, nebulaSession.getSessionID());return nebulaSession;}}}// if session size is less than max size, get session from poolif (sessionList.size() < maxSessionSize) {return createSessionObject(SessionState.USED);}// there's no available session, wait for SessionPoolConfig.getWaitTime and re-gettry {Thread.sleep(sessionPoolConfig.getWaitTime());} catch (InterruptedException e) {log.error("getSession error when wait for idle sessions, ", e);throw new RuntimeException(e);}}// if session size is equal to max size and no idle session here, throw exceptionthrow new RuntimeException("no extra session available");
}
  • 可以调整从sessionList中随机取出nebulaSession
/*** return an idle session*/
private synchronized NebulaSession getSession() throws ClientServerIncompatibleException,AuthFailedException, IOErrorException, BindSpaceFailedException {int retry = sessionPoolConfig.getRetryConnectTimes();while (retry-- >= 0) {// if there are idle sessions, get session from queueif (idleSessionSize.get() > 0) {int[] randomInts = RandomUtil.randomInts(sessionList.size());for (int randomInt : randomInts) {NebulaSession nebulaSession = sessionList.get(randomInt);if (nebulaSession.isIdleAndSetUsed()) {int currentIdleSessionSize = idleSessionSize.decrementAndGet();log.debug("ng session {} {}", currentIdleSessionSize, nebulaSession.getSessionID());return nebulaSession;}}}// if session size is less than max size, get session from poolif (sessionList.size() < maxSessionSize) {return createSessionObject(SessionState.USED);}// there's no available session, wait for SessionPoolConfig.getWaitTime and re-gettry {Thread.sleep(sessionPoolConfig.getWaitTime());} catch (InterruptedException e) {log.error("getSession error when wait for idle sessions, ", e);throw new RuntimeException(e);}}// if session size is equal to max size and no idle session here, throw exceptionthrow new RuntimeException("no extra session available");
}
http://www.dtcms.com/wzjs/821064.html

相关文章:

  • 自己怎么建立网站能下短视频网站做牙
  • 如何做网站推广 求指点建自己的网站多少钱
  • 网站关键词优化推荐贵阳方舟网络6上海网站设计排名
  • 桂林做网站的公司哪家最好比较专业的app开发公司
  • 企业网上申报系统巩义网站优化技巧
  • 凤城市网站建设cms wordpress 区别
  • IT男网站建设周杰伦做的广告网站
  • 有没有做gif的专门网站wordpress主题logo
  • 淘宝网站建设策划案合肥网站建设需要多
  • 设计专业考研平面素材网站软装设计公司加盟
  • 深圳二维码网站建设淘宝客网站html
  • 网站跳出率计算做网站引入字体
  • 商用营销型网站建设python在线编程网址
  • 家电网站源码wordpress 防篡改
  • 新吴区建设局网站宁波高新区建设局网站
  • 网站开发技术支持互站源码交易平台
  • 做图素材网站开通会员哪个好3d动画制作软件手机版
  • 广州品牌网站建设 优美wordpress图像居中
  • 怎么做外贸企业网站哈尔滨网站建设托管公司
  • 公司网站建设费怎么写分录快速备份wordpress
  • 网站设计流程电话wordpress建站课程
  • 做律师网站推广优化哪家好温州市建设小学学校网站
  • 自己创业网站开发淘宝新店怎么快速做起来
  • 网站后台无法上传附件网络营销的特点有
  • wordpress学院主题东莞外贸优化公司
  • 管理系统网站凡科教育
  • 企业官方网站案例wordpress导入用户数据库
  • 提供网站建设设计wordpress食谱主题
  • 南康做网站附近找装修公司
  • 生物科技公司网站模板cn域名注册流程