Commit f053a3cf authored by jsangiamo's avatar jsangiamo
Browse files

enabling async, switchitching to threadpooltaskexecutor to manage threads

parent 841b035c
Pipeline #20206 passed with stages
in 35 minutes and 27 seconds
......@@ -18,6 +18,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.scheduling.annotation.EnableAsync;
/**
* Note: these exclusions are the result of duplicate dependencies being introduced in the
......@@ -32,6 +33,7 @@ import org.springframework.context.annotation.FilterType;
}
)
@SpringBootApplication
@EnableAsync(proxyTargetClass=true)
public class StorageApplication {
public static void main(String[] args) {
SpringApplication.run(StorageApplication.class, args);
......
......@@ -16,8 +16,11 @@ package org.opengroup.osdu.storage.provider.azure.di;
import com.azure.security.keyvault.secrets.SecretClient;
import org.opengroup.osdu.azure.KeyVaultFacade;
import org.opengroup.osdu.storage.di.ThreadPoolFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import javax.inject.Named;
......@@ -94,4 +97,17 @@ public class AzureBootstrapConfig {
return Integer.parseInt(System.getProperty("MIN_WRITES_TO_PARALLELIZE", "10"));
}
@Bean
@Named("asyncProcessExecutor")
public TaskExecutor workExecutor(){
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setThreadNamePrefix("Async-");
// TODO: fine tune these values
threadPoolTaskExecutor.setCorePoolSize(10);
threadPoolTaskExecutor.setMaxPoolSize(100);
threadPoolTaskExecutor.setQueueCapacity(500);
threadPoolTaskExecutor.afterPropertiesSet();
return threadPoolTaskExecutor;
}
}
\ No newline at end of file
......@@ -67,11 +67,8 @@ public class RecordMetadataRepository extends SimpleCosmosStoreRepository<Record
@Autowired
private JaxRsDpsLog logger;
private ExecutorService executorService;
public RecordMetadataRepository() {
super(RecordMetadataDoc.class);
this.executorService = Executors.newFixedThreadPool(10);
}
@Override
......@@ -191,9 +188,9 @@ public class RecordMetadataRepository extends SimpleCosmosStoreRepository<Record
return this.getOne(id, headers.getPartitionId(), cosmosDBName, recordMetadataCollection, id);
}
@Async
private CompletableFuture<RecordMetadataDoc> save(RecordMetadataDoc entity, String partitionId) {
return CompletableFuture.supplyAsync(()->this.save(entity, partitionId,cosmosDBName,recordMetadataCollection,entity.getId()), executorService);
@Async("asyncProcessExecutor")
public CompletableFuture<RecordMetadataDoc> save(RecordMetadataDoc entity, String partitionId) {
return CompletableFuture.supplyAsync(()->this.save(entity, partitionId,cosmosDBName,recordMetadataCollection,entity.getId()));
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment