mirror of
https://github.com/tencentmusic/supersonic.git
synced 2025-12-10 19:51:00 +00: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
|
||||
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")
|
||||
public ThreadPoolExecutor getCommonExecutor() {
|
||||
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 org.springframework.beans.factory.annotation.Autowired;
|
||||
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.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class MetaEmbeddingListener implements ApplicationListener<DataEvent> {
|
||||
public class MetaEmbeddingListener {
|
||||
|
||||
@Autowired
|
||||
private EmbeddingConfig embeddingConfig;
|
||||
@@ -30,8 +30,8 @@ public class MetaEmbeddingListener implements ApplicationListener<DataEvent> {
|
||||
@Value("${s2.embedding.operation.sleep.time:3000}")
|
||||
private Integer embeddingOperationSleepTime;
|
||||
|
||||
@Async
|
||||
@Override
|
||||
@Async("eventExecutor")
|
||||
@EventListener
|
||||
public void onApplicationEvent(DataEvent event) {
|
||||
List<DataItem> dataItems = event.getDataItems();
|
||||
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.helper.HanlpHelper;
|
||||
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.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SchemaDictUpdateListener implements ApplicationListener<DataEvent> {
|
||||
public class SchemaDictUpdateListener {
|
||||
|
||||
@Async
|
||||
@Override
|
||||
@Async("eventExecutor")
|
||||
@EventListener
|
||||
public void onApplicationEvent(DataEvent dataEvent) {
|
||||
if (CollectionUtils.isEmpty(dataEvent.getDataItems())) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user