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

Feature: ExecutorService metrics for spring-boot-starter #548

Open
3 tasks done
s-volkov-1 opened this issue Oct 9, 2024 · 2 comments
Open
3 tasks done

Feature: ExecutorService metrics for spring-boot-starter #548

s-volkov-1 opened this issue Oct 9, 2024 · 2 comments

Comments

@s-volkov-1
Copy link

Prerequisites

  • I am running the latest version
  • I checked the documentation and found no answer
  • I checked to make sure that this issue has not already been filed

Proposal

I am using db-scheduler-spring-boot-starter.
It would be great if default ExecutorService (i.e. workers thread pool) could automatically be attached to micrometer metrics for executors.

Example metrics, which are automatically registered for two default spring's thread pools (for @Async and @Scheduled):

executor_active_threads{name="applicationTaskExecutor"} 1.0
executor_active_threads{name="taskScheduler"} 0.0
executor_pool_size_threads{name="applicationTaskExecutor"} 8.0
executor_pool_size_threads{name="taskScheduler"} 2.0

These executors are exposed as beans and connected to MeterRegistry in TaskExecutorMetricsAutoConfiguration.

So scheduler's ExecutorService could be added as well:

executor_active_threads{name="dbScheduler"} 3.0
executor_pool_size_threads{name="dbScheduler"} 10.0

Workaround

One could take spring's executor (e.g. applicationTaskExecutor) and use it as db-scheduler worker ExecutorService via DbSchedulerCustomizer.executorService()

Thoughts

It seems like ExecutorService was intentionally not exposed as a bean, which possibly prevents it from being registered by TaskExecutorMetricsAutoConfiguration.

Bonus idea: metric returning overdue task count by names

Motivation

With ExecutorService's metrics users could monitor scheduler's load

Context

  • DB-Scheduler Version : 14.0.3 (I also checked what's new in current newest 14.1.0)
  • Spring Boot (check for Yes) : [x] 3.3

Involved classes:

  1. SchedulerBuilder
  2. DbSchedulerCustomizer
  3. DbSchedulerMetricsAutoConfiguration
  4. TaskExecutorMetricsAutoConfiguration (spring boot)
@s-volkov-1
Copy link
Author

s-volkov-1 commented Oct 24, 2024

What I did as a workaround:

@Configuration(proxyBeanMethods = false)
class DbSchedulerConfig(
    private val applicationTaskExecutor: ThreadPoolTaskExecutor
) {
    @Bean
    fun dbSchedulerCustomizer(): DbSchedulerCustomizer = object : DbSchedulerCustomizer {
        // this is needed to register executor service metrics for db-scheduler
        override fun executorService(): Optional<ExecutorService> {
            return Optional.of(applicationTaskExecutor.threadPoolExecutor)
        }
    }
}

application.yml

spring:
  task:
    execution: # ! used as db-scheduler pool !
      pool:
        core-size: 9
        max-size: 9
        allow-core-thread-timeout: false
      thread-name-prefix: task-executor-
      shutdown:
        await-termination: true
        await-termination-period: PT4M # just in case, same as db-scheduler.shutdown-max-wait

db-scheduler:
  # removed thread number setting
  immediate-execution-enabled: true
  shutdown-max-wait: 240s # 4 minutes

And can see executor's load now:
image

@kagkarlsson
Copy link
Owner

PRs for more micrometer instrumentation are welcome :)

Note: It is important that db-scheduler has a dedicated thread-pool (not used by other processes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants