SlideShare una empresa de Scribd logo
1 de 12
Descargar para leer sin conexión
Camel In Action 2nd edition 読書会
2020年9⽉29⽇
13. ParallelProcessing
l 逐次処理
l 複数の処理A,B,Cがあるとき、Exchangeを単⼀スレッドでA,B,Cの順に⾏う
l Exchangeの処理時間は、A,B,C処理時間の合計となる
l 並列処理
l 複数の処理A,B,Cを(ほぼ)同時に⾏うこと
l Exchangeの処理時間は、A,B,Cの何れかの⼀番⻑い処理時間となる
逐次処理/並列処理
20202
Camel Route
連携元
システム
A B C
Consumer
Endpoint
Camel Route
連携元
システム
A
B
C
Consumer
Endpoint
- Multicast
- Split
- Threads
- Wiretap
- など(※)
※ 並列処理をサポートするEIPの⼀覧は、本の「Table 13.4 EIPs in Camel that support parallel processing」を参照
thread1 thread1 thread1
thread1
thread2
thread3
l 読み込んだファイルをSplit使って「⾏」に分割して、1⾏ずつ「⾏
単位の処理」を⾏う
逐次処理 – Splitの例
20203
※ https://github.com/camelinaction/camelinaction2/blob/master/chapter13/bigfile/src/test/java/camelinaction/BigFileTest.java
⾏単位
の処理
l 読み込んだファイルをSplit使って「⾏」に分割して、ThreadPool
のスレッドに割当て最⼤20⾏ずつ「⾏単位の処理」を同時⾏う
並列処理 – Splitの例
20204
※ https://github.com/camelinaction/camelinaction2/blob/master/chapter13/bigfile/src/test/java/camelinaction/BigFileParallelTest.java
⾏単位
の処理
並列処理の有効化
l 並列処理処理時はThreadPool
の仕組みが使⽤される
l CamelのThreadPoolは、
java.util.concurrentを
ベースに拡張
l Camelはデフォルトで、以下の
ThreadPool ProfileからThread
Poolを作成する
並列処理時のThreadPool
20205
オプション デフォルト値 型 説明
poolSize 10 int ExecutorServiceのプールサイズを指定する。
maxPoolSize 20 int ExecutorServiceの最⼤プールサイズを指定する。
keepAliveTime 60 long アクティブではないスレッドを存続させる期間を指定する。
maxQueueSize 1000 int
基になるJava ExecutorServiceのワーカーキューに保持するタスク
の最⼤数を⽰す数値
rejectedPolicy CallerRuns
拒否されたタスクを処理する⽅法を指定する。 以下のオプションが
サポートされている。 ・Abort 例外をスローする ・CallerRuns
呼び出し元で処理する ・Discard タスクを破棄する ・
DiscardOldest キューの中で最も古いデータを破棄する
※ この表は @mkyz08 さんの記事「https://qiita.com/mkyz08/items/e8345af1dd22298724d4」の転載
- poolSize
- maxPoolSize
- keepAliveTime
- rejectedPolicy
- maxQueueSize
l カスタマイズしたThreadPoolを作成して、”executeService”にて参照
すれば良い
並列処理時のThreadPool指定
20206
Java DSL
XML DSL
l カスタマイズしたThreadPool Profileを定義して、”executeService”にて
参照すれば良い
並列処理時のThreadPool Profile指定
20207
XML DSL
Java DSL
l 並列処理の⾏うEIPの”executeService[Ref]”設定によって、ThreadPool
が決定される。
1. ”executeService[Ref]”が設定されてない場合、デフォルトの
ThreadPool ProfileからThreadPoolを作成する
2. ”executeService[Ref]”が設定されている(例: myPool)場合、Bean
Registryにて"myPool"という名前のExecutorService型のBeanを検索
してThreadPoolとして利⽤する
3. Bean Registryにて "myPool" Beanが⾒つからない場合は、
"myPool"という名前のThreadPool Profileを検索して、Profileから
ThreadPoolを⽣成して利⽤する
並列処理時のThreadPoolの決定⽅法
20208
l 同期処理
l 呼び出し元(例: Jetty Consumer)が呼び出
し先(例: ERP)の処理結果返すまで待つ
(Camel内の)同期処理/⾮同期処理
20209
l ⾮同期処理
l 呼び出し元(例: Jetty Consumer)が呼び出し先
(例: ERP)の処理結果返すを待たず別の処理を進
⾏し
l 呼び出し先の処理結果が返ってきたら、元の処
理を継続する
l AHC Camel 2.8: (only producer)
l AWS Camel 2.11: (only consumer) for S3 and SNS.
l Avro Camel 2.10: (only producer)
l CXF Camel 2.5: (both consumer and producer)
l CXFRS Camel 2.5: (only consumer)
l Direct-VM Camel 2.10.5/2.11.0: (both consumer and producer)
l File - (only consumer)
l FTP - (only consumer)
l Guava EventBus Camel 2.10: (only consumer)
l JBI (both consumer and producer)
l Jetty (both consumer and producer)
l JGroups Camel 2.10: (only consumer)
l JMS Camel 2.5: (only producer for Request Reply messaging over
JMS). Camel 2.9: (consumer, if option asyncConsumer=true is used).
l JMS Camel 2.9: (also consumer)
l NMR (both consumer and producer)
l Netty only producer (Camel 2.10: also consumer)
l SEDA (both consumer and producer) SEDA was mistakenly in this list until
November 3rd 2012. As of Camel 2.10.x, it still does not leverage the Async
Routing Engine, but support is planned for Camel 3.0.
l Timer Camel 2.12: (only consumer)
⾮同期処理のサポートするCamelコンポーネント
202010
※ https://camel.apache.org/manual/latest/asynchronous-routing-engine.html
l Processorの実装
l AsyncProcessorインタフェースを実装する
l 詳細は、https://camel.apache.org/manual/latest/async.html
l カスタムコンポーネントの実装
l DefaultAsyncProducer抽象クラスを継承する
l サンプル: https://github.com/camelinaction/camelinaction2/tree/master/chapter13/scalability
⾮同期処理の実装
202011
※ https://www.javadoc.io/doc/org.apache.camel/camel-core/2.23.0/org/apache/camel/AsyncProcessor.html
※ https://www.javadoc.io/doc/org.apache.camel/camel-core/2.23.0/org/apache/camel/impl/DefaultAsyncProducer.html
l 並列処理の使⽤を積極的に
l 並列処理は処理時間を⼤幅に短縮できます。しかし、並列処理をを使う場合、以
下の点を注意してください。
1. スレッドセーフな変数を使うこと
2. 呼び出し先のロジックも並⾏して処理できるのが必要
3. 処理の順序性が失うこと
l ThreadPoolの調整は慎重に
l 多くの場合、デフォルト設定をお勧めします。
l ThreadPool調整後の変化が測定できる場合のみ、ThreadPoolを微調整します。
l スケーラビリティ性が求められる場合、⾮同期処理を使⽤する
l この場合、⾮同期処理モデルをサポートするCamelコンポーネントを使⽤してみ
てください。
l 独⾃の⾮同期コンポーネントを実装する場合は、Camelコンポーネントの実装
ルールに従って構造化する必要があります。これにより、メッセージを受信した
時、またはタイムアウトが発⽣した時でも、Camelがメッセージをルーティング
できるようになり、スレッドがスタックするという潜在的な問題が回避されます。
l リアクティブシステム
l リアクティブストリームとフレームワークの⼈気が⾼まっています。これらを
Camelで使⽤する⽅法については、第20章(オンラインで⼊⼿可能)を参照して
ください。
並列処理・⾮同期処理のベストプラクティス
202012

Más contenido relacionado

Destacado

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destacado (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

13. parallel processing

  • 1. Camel In Action 2nd edition 読書会 2020年9⽉29⽇ 13. ParallelProcessing
  • 2. l 逐次処理 l 複数の処理A,B,Cがあるとき、Exchangeを単⼀スレッドでA,B,Cの順に⾏う l Exchangeの処理時間は、A,B,C処理時間の合計となる l 並列処理 l 複数の処理A,B,Cを(ほぼ)同時に⾏うこと l Exchangeの処理時間は、A,B,Cの何れかの⼀番⻑い処理時間となる 逐次処理/並列処理 20202 Camel Route 連携元 システム A B C Consumer Endpoint Camel Route 連携元 システム A B C Consumer Endpoint - Multicast - Split - Threads - Wiretap - など(※) ※ 並列処理をサポートするEIPの⼀覧は、本の「Table 13.4 EIPs in Camel that support parallel processing」を参照 thread1 thread1 thread1 thread1 thread2 thread3
  • 3. l 読み込んだファイルをSplit使って「⾏」に分割して、1⾏ずつ「⾏ 単位の処理」を⾏う 逐次処理 – Splitの例 20203 ※ https://github.com/camelinaction/camelinaction2/blob/master/chapter13/bigfile/src/test/java/camelinaction/BigFileTest.java ⾏単位 の処理
  • 4. l 読み込んだファイルをSplit使って「⾏」に分割して、ThreadPool のスレッドに割当て最⼤20⾏ずつ「⾏単位の処理」を同時⾏う 並列処理 – Splitの例 20204 ※ https://github.com/camelinaction/camelinaction2/blob/master/chapter13/bigfile/src/test/java/camelinaction/BigFileParallelTest.java ⾏単位 の処理 並列処理の有効化
  • 5. l 並列処理処理時はThreadPool の仕組みが使⽤される l CamelのThreadPoolは、 java.util.concurrentを ベースに拡張 l Camelはデフォルトで、以下の ThreadPool ProfileからThread Poolを作成する 並列処理時のThreadPool 20205 オプション デフォルト値 型 説明 poolSize 10 int ExecutorServiceのプールサイズを指定する。 maxPoolSize 20 int ExecutorServiceの最⼤プールサイズを指定する。 keepAliveTime 60 long アクティブではないスレッドを存続させる期間を指定する。 maxQueueSize 1000 int 基になるJava ExecutorServiceのワーカーキューに保持するタスク の最⼤数を⽰す数値 rejectedPolicy CallerRuns 拒否されたタスクを処理する⽅法を指定する。 以下のオプションが サポートされている。 ・Abort 例外をスローする ・CallerRuns 呼び出し元で処理する ・Discard タスクを破棄する ・ DiscardOldest キューの中で最も古いデータを破棄する ※ この表は @mkyz08 さんの記事「https://qiita.com/mkyz08/items/e8345af1dd22298724d4」の転載 - poolSize - maxPoolSize - keepAliveTime - rejectedPolicy - maxQueueSize
  • 8. l 並列処理の⾏うEIPの”executeService[Ref]”設定によって、ThreadPool が決定される。 1. ”executeService[Ref]”が設定されてない場合、デフォルトの ThreadPool ProfileからThreadPoolを作成する 2. ”executeService[Ref]”が設定されている(例: myPool)場合、Bean Registryにて"myPool"という名前のExecutorService型のBeanを検索 してThreadPoolとして利⽤する 3. Bean Registryにて "myPool" Beanが⾒つからない場合は、 "myPool"という名前のThreadPool Profileを検索して、Profileから ThreadPoolを⽣成して利⽤する 並列処理時のThreadPoolの決定⽅法 20208
  • 9. l 同期処理 l 呼び出し元(例: Jetty Consumer)が呼び出 し先(例: ERP)の処理結果返すまで待つ (Camel内の)同期処理/⾮同期処理 20209 l ⾮同期処理 l 呼び出し元(例: Jetty Consumer)が呼び出し先 (例: ERP)の処理結果返すを待たず別の処理を進 ⾏し l 呼び出し先の処理結果が返ってきたら、元の処 理を継続する
  • 10. l AHC Camel 2.8: (only producer) l AWS Camel 2.11: (only consumer) for S3 and SNS. l Avro Camel 2.10: (only producer) l CXF Camel 2.5: (both consumer and producer) l CXFRS Camel 2.5: (only consumer) l Direct-VM Camel 2.10.5/2.11.0: (both consumer and producer) l File - (only consumer) l FTP - (only consumer) l Guava EventBus Camel 2.10: (only consumer) l JBI (both consumer and producer) l Jetty (both consumer and producer) l JGroups Camel 2.10: (only consumer) l JMS Camel 2.5: (only producer for Request Reply messaging over JMS). Camel 2.9: (consumer, if option asyncConsumer=true is used). l JMS Camel 2.9: (also consumer) l NMR (both consumer and producer) l Netty only producer (Camel 2.10: also consumer) l SEDA (both consumer and producer) SEDA was mistakenly in this list until November 3rd 2012. As of Camel 2.10.x, it still does not leverage the Async Routing Engine, but support is planned for Camel 3.0. l Timer Camel 2.12: (only consumer) ⾮同期処理のサポートするCamelコンポーネント 202010 ※ https://camel.apache.org/manual/latest/asynchronous-routing-engine.html
  • 11. l Processorの実装 l AsyncProcessorインタフェースを実装する l 詳細は、https://camel.apache.org/manual/latest/async.html l カスタムコンポーネントの実装 l DefaultAsyncProducer抽象クラスを継承する l サンプル: https://github.com/camelinaction/camelinaction2/tree/master/chapter13/scalability ⾮同期処理の実装 202011 ※ https://www.javadoc.io/doc/org.apache.camel/camel-core/2.23.0/org/apache/camel/AsyncProcessor.html ※ https://www.javadoc.io/doc/org.apache.camel/camel-core/2.23.0/org/apache/camel/impl/DefaultAsyncProducer.html
  • 12. l 並列処理の使⽤を積極的に l 並列処理は処理時間を⼤幅に短縮できます。しかし、並列処理をを使う場合、以 下の点を注意してください。 1. スレッドセーフな変数を使うこと 2. 呼び出し先のロジックも並⾏して処理できるのが必要 3. 処理の順序性が失うこと l ThreadPoolの調整は慎重に l 多くの場合、デフォルト設定をお勧めします。 l ThreadPool調整後の変化が測定できる場合のみ、ThreadPoolを微調整します。 l スケーラビリティ性が求められる場合、⾮同期処理を使⽤する l この場合、⾮同期処理モデルをサポートするCamelコンポーネントを使⽤してみ てください。 l 独⾃の⾮同期コンポーネントを実装する場合は、Camelコンポーネントの実装 ルールに従って構造化する必要があります。これにより、メッセージを受信した 時、またはタイムアウトが発⽣した時でも、Camelがメッセージをルーティング できるようになり、スレッドがスタックするという潜在的な問題が回避されます。 l リアクティブシステム l リアクティブストリームとフレームワークの⼈気が⾼まっています。これらを Camelで使⽤する⽅法については、第20章(オンラインで⼊⼿可能)を参照して ください。 並列処理・⾮同期処理のベストプラクティス 202012