mirror of
https://github.com/tencentmusic/supersonic.git
synced 2026-04-27 10:54:21 +08:00
[improvement][headless]Setup thread pool for data event listeners.
This commit is contained in:
@@ -11,6 +11,14 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Component
|
@Component
|
||||||
public class ThreadPoolConfig {
|
public class ThreadPoolConfig {
|
||||||
|
|
||||||
|
@Bean("eventExecutor")
|
||||||
|
public ThreadPoolExecutor getTaskEventExecutor() {
|
||||||
|
return new ThreadPoolExecutor(4, 8, 60 * 3, TimeUnit.SECONDS,
|
||||||
|
new LinkedBlockingQueue<>(1024),
|
||||||
|
new ThreadFactoryBuilder().setNameFormat("supersonic-event-pool-").build(),
|
||||||
|
new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
|
}
|
||||||
|
|
||||||
@Bean("commonExecutor")
|
@Bean("commonExecutor")
|
||||||
public ThreadPoolExecutor getCommonExecutor() {
|
public ThreadPoolExecutor getCommonExecutor() {
|
||||||
return new ThreadPoolExecutor(8, 16, 60 * 3, TimeUnit.SECONDS,
|
return new ThreadPoolExecutor(8, 16, 60 * 3, TimeUnit.SECONDS,
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import dev.langchain4j.store.embedding.TextSegmentConvert;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
@@ -19,7 +19,7 @@ import java.util.List;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class MetaEmbeddingListener implements ApplicationListener<DataEvent> {
|
public class MetaEmbeddingListener {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EmbeddingConfig embeddingConfig;
|
private EmbeddingConfig embeddingConfig;
|
||||||
@@ -30,8 +30,8 @@ public class MetaEmbeddingListener implements ApplicationListener<DataEvent> {
|
|||||||
@Value("${s2.embedding.operation.sleep.time:3000}")
|
@Value("${s2.embedding.operation.sleep.time:3000}")
|
||||||
private Integer embeddingOperationSleepTime;
|
private Integer embeddingOperationSleepTime;
|
||||||
|
|
||||||
@Async
|
@Async("eventExecutor")
|
||||||
@Override
|
@EventListener
|
||||||
public void onApplicationEvent(DataEvent event) {
|
public void onApplicationEvent(DataEvent event) {
|
||||||
List<DataItem> dataItems = event.getDataItems();
|
List<DataItem> dataItems = event.getDataItems();
|
||||||
if (CollectionUtils.isEmpty(dataItems)) {
|
if (CollectionUtils.isEmpty(dataItems)) {
|
||||||
|
|||||||
@@ -7,17 +7,17 @@ import com.tencent.supersonic.common.pojo.enums.EventType;
|
|||||||
import com.tencent.supersonic.headless.chat.knowledge.DictWord;
|
import com.tencent.supersonic.headless.chat.knowledge.DictWord;
|
||||||
import com.tencent.supersonic.headless.chat.knowledge.helper.HanlpHelper;
|
import com.tencent.supersonic.headless.chat.knowledge.helper.HanlpHelper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.event.EventListener;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SchemaDictUpdateListener implements ApplicationListener<DataEvent> {
|
public class SchemaDictUpdateListener {
|
||||||
|
|
||||||
@Async
|
@Async("eventExecutor")
|
||||||
@Override
|
@EventListener
|
||||||
public void onApplicationEvent(DataEvent dataEvent) {
|
public void onApplicationEvent(DataEvent dataEvent) {
|
||||||
if (CollectionUtils.isEmpty(dataEvent.getDataItems())) {
|
if (CollectionUtils.isEmpty(dataEvent.getDataItems())) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user