Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE-INFRA] Tomcat thread pool 및 MongoDB connection pool 설정 #420

Open
wants to merge 4 commits into
base: be/develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package com.pokerogue.helper.global.config;

import com.mongodb.ConnectionString;
import com.mongodb.MongoClientSettings;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import com.pokerogue.helper.biome.converter.TierConverter;
import com.pokerogue.helper.move.converter.FlagConverter;
import com.pokerogue.helper.move.converter.MoveCategoryConverter;
import com.pokerogue.helper.move.converter.MoveTargetConverter;
import com.pokerogue.helper.pokemon.converter.EvolutionItemConverter;
import com.pokerogue.helper.type.converter.TypeReadConverter;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
Expand All @@ -16,6 +24,9 @@
@EnableMongoRepositories(basePackages = {"com.pokerogue"})
public class DataMongoDbConfig {

@Value("${spring.data.mongodb.uri}")
private String uri;

@Bean
public MongoCustomConversions customConversions() {
return new MongoCustomConversions(List.of(
Expand All @@ -27,4 +38,19 @@ public MongoCustomConversions customConversions() {
new TierConverter()
));
}

@Bean
public MongoClient mongoClient() {
ConnectionString connectionString = new ConnectionString(uri);
MongoClientSettings settings = MongoClientSettings.builder()
.applyConnectionString(connectionString)
.applyToConnectionPoolSettings(builder -> builder
.maxSize(10)
.minSize(10)
.maxWaitTime(2, TimeUnit.SECONDS)
)
.build();

return MongoClients.create(settings);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import com.pokerogue.helper.pokemon.data.Pokemon;
import jakarta.annotation.PostConstruct;

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -36,6 +38,7 @@ public void refreshCache() {
public List<Pokemon> findAll() {
return pokemons.values()
.stream()
.sorted(Comparator.comparingInt(Pokemon::getPokedexNumber))
.toList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import com.pokerogue.helper.pokemon.repository.PokemonInMemoryRepository;
import com.pokerogue.helper.type.data.Type;
import com.pokerogue.helper.type.dto.PokemonTypeResponse;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -78,7 +80,7 @@ private List<PokemonTypeResponse> createTypeResponse(Pokemon pokemon) {
}

private List<PokemonAbilityResponse> createAbilityResponse(Pokemon pokemon) {
List<String> abilityIds = pokemon.getNormalAbilityIds();
List<String> abilityIds = new ArrayList<>(pokemon.getNormalAbilityIds());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멀티 스레드 테스트를 하며 abilityIds 를 get해서 add하는 로직에서 ConcurrentModificationException이 발생했습니다. 해결하기 위해 서비스 로직에서 복사를 해줬는데 추후 모든 데이터 클래스들에 방어적 복사를 적용하면 좋겠네요 ☺️

abilityIds.add(pokemon.getPassiveAbilityId());
abilityIds.add(pokemon.getHiddenAbilityId());

Expand Down
2 changes: 1 addition & 1 deletion backend/pokerogue/src/main/resources
Loading