ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • CustomExecutionContext 설정
    scala/playframework 2023. 3. 1. 22:13

    Custom ExecutionContext 생성

    import akka.actor.ActorSystem
    import play.api.libs.concurrent.CustomExecutionContext
    
    class PostExecutionContext @Inject()(actorSystem: ActorSystem)
        extends CustomExecutionContext(actorSystem, "repository.dispatcher")

     

    application.conf 에 ExecutionContext 설정

    repository.dispatcher {
      executor = "thread-pool-executor"
      throughput = 1
      thread-pool-executor {
        fixed-pool-size = 40
      }
    }
    
    ## 참고: https://www.playframework.com/documentation/2.8.x/ThreadPools#Highly-synchronous
    akka {
      actor {
        default-dispatcher {
          executor = "thread-pool-executor"
          throughput = 1
          thread-pool-executor {
            fixed-pool-size = 55 # db conn pool (50) + number of cores (4) + housekeeping (1)
          }
        }
      }
    }

     

    ExecutionContext 사용

    import javax.inject.{Inject, Singleton}
    
    import akka.actor.ActorSystem
    import play.api.libs.concurrent.CustomExecutionContext
    import play.api.{Logger, MarkerContext}
    
    import scala.concurrent.Future
    
    
    @Singleton
    class PostRepositoryImpl @Inject()()(implicit ec: PostExecutionContext) {
      def create(data: PostData)(implicit mc: MarkerContext): Future[PostId] = {
        Future {
          logger.trace(s"create: data = $data")
          data.id
        }
      }
    }

     

    참고: https://www.playframework.com/documentation/2.8.x/ThreadPools

    'scala > playframework' 카테고리의 다른 글

    Tapir + Playframework  (0) 2023.06.19
    ScalaTest  (0) 2023.02.19
    Using ScalikeJDBC  (0) 2023.02.19
    Logging MDC  (0) 2023.02.19
    Deploy  (0) 2023.02.19

    댓글

Designed by Tistory.