Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
一体いつから ――― DataLoader が 並列実行されていると錯覚していた?
Search
SMS tech
June 24, 2025
580
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
一体いつから ――― DataLoader が 並列実行されていると錯覚していた?
SMS tech
June 24, 2025
More Decks by SMS tech
See All by SMS tech
DatadogのBits Chatが開発組織にもたらしたもの / What Bits Chat Has Brought Us
sms_tech
1
370
バーティカルドメインのデザイナー視点で 読み解く Figma Config 2026 / vertical domain designer take on figma config 2026
sms_tech
0
410
PR単位で使い捨てるカイポケコネクトのpreview環境の設計と運用/ ephemeral preview environments per pr
sms_tech
2
4.6k
Bits Chat on Development
sms_tech
0
1.8k
オンコールの負荷軽減のためのBits Assistant 活用方法 / How to Use Bits Assistant to Reduce the Workload on On-Call Staff
sms_tech
1
710
AWS DevOps Agent vs SRE俺 / AWS DevOps Agent vs me, the SRE
sms_tech
3
1.5k
カイポケコネクトのフロントエンドコミュニティとGraphQLスタックの更新/advancing-the-graphql-stack-update-in-the-frontend-community
sms_tech
0
240
フロントエンド専任がいないチームのNext.js移行と、その後/Renewal to Next.js for a team without a dedicated front-end developer, and what happened next
sms_tech
0
210
マルチプロダクトのカオスを制す。「プロダクトディシジョンレコード」で実現するチーム横断のアラインメント戦略/Introduction to Product Decision Record
sms_tech
0
3.5k
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
97
6.8k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
900
What does AI have to do with Human Rights?
axbom
PRO
1
2.4k
Visualization
eitanlees
153
17k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
How to make the Groovebox
asonas
2
2.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
350
The Language of Interfaces
destraynor
162
27k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.6k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
310
Transcript
0 © SMS Co., Ltd. 2025.06.25 【非公式】 JJUG CCC 2025
Spring 後夜祭 LT 株式会社エス・エム・エス プロダクト推進本部 @hmarui66 一体いつから ――― DataLoader が 並列実行されていると錯覚していた?
1 © SMS Co., Ltd. Spring for GraphQL 使ってます
2 © SMS Co., Ltd. Spring for GraphQL 使ってます アノテーションでスキーマとマッピング
(プラグイン入れたら ✡アイコンで相互にジャンプ可能)
3 © SMS Co., Ltd. Spring for GraphQL 使ってます `@BatchMapping`
は暗黙的に DataLoader を 使用して N+1 問題を回避してくれる(便利) 参考: https://spring.pleiades.io/spring-graphql/reference/controllers.html#controllers.batch-mapping
4 © SMS Co., Ltd. クエリ処理の流れ こんなクエリを実行→
5 © SMS Co., Ltd. クエリ処理の流れ `books` のクエリが呼ばれるので
6 © SMS Co., Ltd. クエリ処理の流れ `@QueryMapping` がつけられた メソッドが呼び出される
7 © SMS Co., Ltd. クエリ処理の流れ `author`, `publisher` も取得対象なので
8 © SMS Co., Ltd. クエリ処理の流れ `@BatchMapping` がつけられた メソッドが呼び出される
9 © SMS Co., Ltd. クエリ処理の流れ `author`, `publisher` は独立したフィールドなので 並列で取得されるはず?
10 © SMS Co., Ltd. クエリ処理の流れ 🙅 デフォルトでは同期的に呼ばれ、 直列実行
11 © SMS Co., Ltd. クエリ処理の流れ (このサンプルでは) `publisher` → `author`
と直列で実行 ※OpenTelemetry の Java Agent を仕込んで可視化
12 © SMS Co., Ltd. 並列実行するには
13 © SMS Co., Ltd. 並列実行するには Java 21+ では、AnnotatedControllerConfigurer が
Executor で構成されている場合、 ブロッキングメソッドシグネチャーを持つコントローラーメソッドが 非同期的に呼び出されます。 ドキュメントによると... 参考: https://spring.pleiades.io/spring-graphql/reference/controllers.html#controllers.schema-mapping.return.values → AnnotatedControllerConfigurer をカスタムすればいけそう
14 © SMS Co., Ltd. 並列実行するには こんな感じで AnnotatedControllerConfigurer を Executor
とともに設定
15 © SMS Co., Ltd. 並列で実行されるようになった 🎉🎉🎉 並列実行するには
16 © SMS Co., Ltd. 実はドキュメントには、こうも書かれている 並列実行するには Spring for GraphQL
の Spring Boot スターターは、 プロパティ spring.threads.virtual.enabled が設定されている場合、仮想スレッドの Executor を使 用して AnnotatedControllerConfigurer を自動的に構成します。 参考: https://spring.pleiades.io/spring-graphql/reference/controllers.html#controllers.schema-mapping.return.values → Virtual Threads を有効化すると自動的に非同期実行!!!
17 © SMS Co., Ltd. ちょっと込み入った話
18 © SMS Co., Ltd. 実はデフォルトでも AnnotatedControllerConfigure の Executor はセットされている
ちょっと込み入った話 参考: https://github.com/spring-projects/spring-boot/blob/740362d3941a0952a7e92183a96c9ef28ef46de0/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/spri ngframework/boot/autoconfigure/task/TaskExecutorConfigurations.java#L59-L65 https://github.com/spring-projects/spring-boot/blob/740362d3941a0952a7e92183a96c9ef28ef46de0/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/spri ngframework/boot/autoconfigure/graphql/GraphQlAutoConfiguration.java#L155-L166
19 © SMS Co., Ltd. AnnotatedControllerConfigure の DataLoader の設定箇所の `shouldInvokeAsync`
に注目 ちょっと込み入った話 参考: https://github.com/spring-projects/spring-graphql/blob/7ee16217f76fc92240e89ee781607acf3ca0981c/spring-graphql/src/main/java/org/springframework/graphql/data/m ethod/annotation/support/AnnotatedControllerConfigurer.java#L346-L393 https://github.com/spring-projects/spring-graphql/blob/7ee16217f76fc92240e89ee781607acf3ca0981c/spring-graphql/src/main/java/org/springframework/graphql/data/m ethod/annotation/support/AnnotatedControllerDetectionSupport.java#L302-L305 「Executor が SchedulingTaskExecutor && prefersShortLivedTasks が true」ではない場合、非 同期で実行される
20 © SMS Co., Ltd. デフォルトの Executor の設定箇所、再掲 ちょっと込み入った話 ここで
build される ThreadPoolTaskExecutor は SchedulingTaskExecutor を実装。 そして、SchedulingTaskExecutor は prefersShortLivedTasks を true 固定。 →前のページの `shouldInvokeAsync` が false となり、非同期実行されず直列処理
21 © SMS Co., Ltd. リポジトリを見ると Virtual Threads 対応はされてい る...?🤔
参考: https://github.com/DataDog/dd-trace-java/pull/6789 Virtual Threads を有効にすると Datadog の javaagent でトレースが途切れる問題がある。 ※dd-java-agent-1.49.0 現在 ちょっと込み入った話 2
22 © SMS Co., Ltd. 参考: https://github.com/spring-projects/spring-boot/blob/740362 d3941a0952a7e92183a96c9ef28ef46de0/spring-boot-proje ct/spring-boot-autoconfigure/src/main/java/org/springframe work/boot/autoconfigure/task/TaskExecutorConfigurations.j
ava#L52-L57 参考: https://github.com/DataDog/dd-trace-java/blob/56844c2a3f b79bb9ece1f6a9078bb36e9e7d3939/dd-java-agent/instru mentation/java-concurrent/src/main/java/datadog/trace/inst rumentation/java/concurrent/TaskRunnerInstrumentation.ja va#L27-L30 Virtual Threads サポートの PR での計装対象は `ThreadPerTaskExecutor` だが... ちょっと込み入った話 2 Spring の AutoConfigure はデフォルトで `SimpleAsyncTaskExecutor` を設定してる →計装漏れにつながってそう? ※AnnotatedControllerConfigurer#setExecutor に Executors.newVirtualThreadPerTaskExecutor() を渡したら 途切れなかったので、そうっぽい
23 © SMS Co., Ltd. おしまい 動作確認に使ったサンプルプロジェクト : https://github.com/hmarui66/sprint-graphql/tree/lt ※main
ブランチはとっ散らかっているので lt ブランチを見てください