Browse Source

feat:

1. 修改线上环境线程池配置;
tags/24111501^0
WendyYang 1 month ago
parent
commit
25768282a0
7 changed files with 38 additions and 5 deletions
  1. +7
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/handler/GlobalExceptionHandler.java
  2. +5
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/common/helper/basic/AbstractRegionCacheHelper.java
  3. +5
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractDictionaryCache.java
  4. +5
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractTagsCache.java
  5. +6
    -1
      hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/utils/ProjectIdCodeCacheUtil.java
  6. +5
    -0
      hz-pm-api/src/main/java/com/hz/pm/api/user/helper/impl/MhUnitCacheImpl.java
  7. +5
    -4
      hz-pm-api/src/main/resources/application-prod.yml

+ 7
- 0
hz-pm-api/src/main/java/com/hz/pm/api/common/handler/GlobalExceptionHandler.java View File

@@ -5,6 +5,7 @@ import com.ningdatech.basic.enumeration.Status;
import com.ningdatech.basic.exception.BizException; import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.model.ApiResponse; import com.ningdatech.basic.model.ApiResponse;
import com.ningdatech.basic.util.CollUtils; import com.ningdatech.basic.util.CollUtils;
import com.wflow.exception.BusinessException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
@@ -84,4 +85,10 @@ public class GlobalExceptionHandler {
return ApiResponse.of(ERROR_CODE, e.getMessage()); return ApiResponse.of(ERROR_CODE, e.getMessage());
} }


@ResponseBody
@ExceptionHandler(value = BusinessException.class)
public ApiResponse<Void> catchException(BusinessException e) {
return ApiResponse.of(ERROR_CODE, e.getMessage());
}

} }

+ 5
- 0
hz-pm-api/src/main/java/com/hz/pm/api/common/helper/basic/AbstractRegionCacheHelper.java View File

@@ -1,5 +1,6 @@
package com.hz.pm.api.common.helper.basic; package com.hz.pm.api.common.helper.basic;


import cn.hutool.core.date.StopWatch;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache; import com.github.benmanes.caffeine.cache.LoadingCache;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@@ -68,7 +69,11 @@ public abstract class AbstractRegionCacheHelper implements InitializingBean {
return RegionConverter.toRegionDTO(region); return RegionConverter.toRegionDTO(region);
}); });
// 初始化所有区域数据到缓存 // 初始化所有区域数据到缓存
StopWatch watch = new StopWatch();
watch.start();
initRegionCache(); initRegionCache();
watch.stop();
log.info("初始化区域缓存耗时:{} ms", watch.getTotalTimeMillis());
} }


public String getParentCodeRoot() { public String getParentCodeRoot() {


+ 5
- 0
hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractDictionaryCache.java View File

@@ -2,6 +2,7 @@ package com.hz.pm.api.meta.helper.basic;


import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.IterUtil; import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.date.StopWatch;
import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache; import com.github.benmanes.caffeine.cache.LoadingCache;
@@ -66,10 +67,14 @@ public abstract class AbstractDictionaryCache implements InitializingBean, Dicti
} }


private void initAllDicts() { private void initAllDicts() {
StopWatch watch = new StopWatch();
watch.start();
List<String> dictTypes = Arrays.stream(DictTypeEnum.values()) List<String> dictTypes = Arrays.stream(DictTypeEnum.values())
.map(DictTypeEnum::getKey) .map(DictTypeEnum::getKey)
.collect(Collectors.toList()); .collect(Collectors.toList());
dictCache.getAll(dictTypes); dictCache.getAll(dictTypes);
watch.stop();
log.info("初始化字典数据耗时:{} ms", watch.getTotalTimeMillis());
} }


} }

+ 5
- 0
hz-pm-api/src/main/java/com/hz/pm/api/meta/helper/basic/AbstractTagsCache.java View File

@@ -2,6 +2,7 @@ package com.hz.pm.api.meta.helper.basic;


import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.IterUtil; import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
@@ -102,10 +103,14 @@ public abstract class AbstractTagsCache implements InitializingBean, TagCache {
} }


public void initAllTags() { public void initAllTags() {
StopWatch watch = new StopWatch();
watch.start();
List<String> allLevels = Arrays.stream(NumberUtil.range(1, MAX_LEVEL)) List<String> allLevels = Arrays.stream(NumberUtil.range(1, MAX_LEVEL))
.mapToObj(String::valueOf) .mapToObj(String::valueOf)
.collect(Collectors.toList()); .collect(Collectors.toList());
tagsCache.getAll(allLevels); tagsCache.getAll(allLevels);
watch.stop();
log.info("初始化标签树耗时:{} ms", watch.getTotalTimeMillis());
} }


protected List<TagTreeDTO> getChildren(String tagCode, List<TagTreeDTO> list) { protected List<TagTreeDTO> getChildren(String tagCode, List<TagTreeDTO> list) {


+ 6
- 1
hz-pm-api/src/main/java/com/hz/pm/api/projectdeclared/utils/ProjectIdCodeCacheUtil.java View File

@@ -1,5 +1,6 @@
package com.hz.pm.api.projectdeclared.utils; package com.hz.pm.api.projectdeclared.utils;


import cn.hutool.core.date.StopWatch;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -45,12 +46,16 @@ public class ProjectIdCodeCacheUtil {


@PostConstruct @PostConstruct
public void initProjectIdCodeCache() { public void initProjectIdCodeCache() {
StopWatch watch = new StopWatch();
watch.start();
Wrapper<Project> query = Wrappers.lambdaQuery(Project.class) Wrapper<Project> query = Wrappers.lambdaQuery(Project.class)
.select(Project::getProjectCode, Project::getId, Project::getCreateOn, Project::getNewest); .select(Project::getProjectCode, Project::getId, Project::getCreateOn, Project::getNewest);
for (Project project : projectService.list(query)) { for (Project project : projectService.list(query)) {
put(project.getId(), project, false); put(project.getId(), project, false);
} }
log.info("初始化项目ID编码缓存:{}", CACHE.size());
watch.stop();
log.info("初始化项目ID编码缓存耗时:{} ms", watch.getTotalTimeMillis());
log.info("初始化项目ID编码缓存:{} 个", CACHE.size());
} }


//================================================================================================================== //==================================================================================================================


+ 5
- 0
hz-pm-api/src/main/java/com/hz/pm/api/user/helper/impl/MhUnitCacheImpl.java View File

@@ -3,6 +3,7 @@ package com.hz.pm.api.user.helper.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.IterUtil; import cn.hutool.core.collection.IterUtil;
import cn.hutool.core.date.StopWatch;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.Caffeine;
@@ -96,7 +97,11 @@ public class MhUnitCacheImpl implements MhUnitCache, InitializingBean {
} }
}); });
// 初始化所有单位 // 初始化所有单位
StopWatch watch = new StopWatch();
watch.start();
cache.getAll(Collections.singletonList(ALL)); cache.getAll(Collections.singletonList(ALL));
watch.stop();
log.info("初始化单位缓存耗时:{} ms", watch.getTotalTimeMillis());
} }


@Override @Override


+ 5
- 4
hz-pm-api/src/main/resources/application-prod.yml View File

@@ -96,6 +96,7 @@ nd:
log: log:
enabled: true enabled: true
type: DB type: DB
keep-days: 365
# 文件存储 # 文件存储
file: file:
storage-type: ALI_OSS storage-type: ALI_OSS
@@ -235,20 +236,20 @@ thread-pool-util:
keep-alive-seconds: 120 keep-alive-seconds: 120
thread-name-prefix: request-executor- thread-name-prefix: request-executor-
scheduler: scheduler:
core-pool-size: 4
core-pool-size: 3
thread-name-prefix: scheduler-executor- thread-name-prefix: scheduler-executor-


# 工作流线程池配置 # 工作流线程池配置
wflow-thread-pool-util: wflow-thread-pool-util:
scheduler: scheduler:
core-pool-size: 4
core-pool-size: 3
thread-name-prefix: wflow-thread-scheduler- thread-name-prefix: wflow-thread-scheduler-
executor: executor:
core-pool-size: 4
core-pool-size: 3
thread-name-prefix: wflow-thread-executor- thread-name-prefix: wflow-thread-executor-
queue-capacity: 300 queue-capacity: 300
keep-alive-seconds: 120 keep-alive-seconds: 120
max-pool-size: 8
max-pool-size: 6
random-invite: random-invite:
thread-pool-properties: thread-pool-properties:
core-pool-size: 3 core-pool-size: 3


Loading…
Cancel
Save