---
title: "エージェント"
slug: "agents"
abstract: ""
---
# エージェント

エージェントはCortex処理エンジン(Processing Engine)内の作業処理を担当します。各エージェントはスレッドを表し、並列実行に設定できます。処理エンジンは複数のデフォルトエージェントを搭載しており、タスクエージェントは定期的にCortex処理エンジンのタスクデータベースをポーリングし、ワーカーにそれらのタスクを実行するよう呼びかけます。

開発者として、あなたは以下のようなことができます:

-   既存のエージェントを設定するなど、タスクエージェントのスケーリング方法を変更できます。
-   カスタムエージェントを作成しましょう。

## エージェント基底クラス

すべてのエージェントはIAgentを実装しています。さらに、2つの基本クラスが利用可能です:

-   BaseAgent 基本的な機能とサービスを提供します。 BaseAgent を継承するエージェントは定期的な間隔で動作するわけではなく、エンジン起動時に起動し、イベントが発生するまでスリープすることがあります。
-   RecurringAgent継承 BaseAgent。継承 RecurringAgent エージェントは規則的かつ設定可能な間隔で実行されます。ほとんどのデフォルトエージェントは RecurringAgentを継承します。

## エージェントの設定オプション

エージェントは \\\\App\_Data\\\\Config\\Sitecore\\Processing/scに登録されています。Processing.Engine.Services.xml設定ファイルです。エージェントを設定する方法は2つあります。

-   シンプルな設定は単一のエージェントを登録します。
-   並列エージェントの設定では、複数のエージェントを手動または利用可能なコア数に応じて登録できます。

継承するエージェントは起動時に一度BaseAgent実行されます。継承するエージェントは設定可能な間隔でRecurringAgent実行されます。

## 単純なエージェント構成

以下の例は、単一のタスククリーンアップエージェント(TaskCleanupAgent)を登録する方法を示しています。タスククリーンアップエージェントはRecurringAgentを継承し、エージェントがどれくらいの頻度で実行すべきかを決定するSleepPeriod設定を期待します。

<Settings>
 <Sitecore>
 <Processing>
 <Services>
 <TaskCleanupAgent>
 <Type>Sitecore.Processing.Engine.Agents.TaskCleanupAgent, Sitecore.Processing.Engine</Type>
 <As>Sitecore.Processing.Engine.Abstractions.IAgent, Sitecore.Processing.Engine.Abstractions</As>
 <LifeTime>Transient</LifeTime>
 <Options>
 <!-- The period which the agent sleeps before running again. -->
 <SleepPeriod>0.\`00:00\`:14.000</SleepPeriod>
 </Options>
 </TaskCleanupAgent>
 </Services>
 </Processing>
 </Sitecore>
</Settings>

> !注RecurringAgentを継承しないエージェントはSleepPeriod設定を必要としません。

## 並列エージェントの設定

以下の例は、TaskAgentを例に複数のエージェントを登録する方法を示しています。

<Settings>
 <Sitecore>
 <Processing>
 <Services>
 <TaskAgents> <!-- Name of agent -->
 <Type>Sitecore.Processing.Engine.Agents.ParallelAgentsConfiguration, Sitecore.Processing.Engine</Type>
 <As>Sitecore.XConnect.DependencyInjection.Abstractions.IXConnectServicesConfiguration, Sitecore.XConnect.DependencyInjection</As>
 <LifeTime>Transient</LifeTime>
 <Options>
 <!-- The fixed number of agents to register. These are in addition to the agents registered by the AgentCoreRatio option. -->
 <AgentFixedCount>0</AgentFixedCount>
 <!-- The ratio of the count of agents to CPU cores to register. These are in addition to the agents registered by the AgentFixedCount option. -->
 <AgentCoreRatio>0.75</AgentCoreRatio>
 <!-- The configuration for the agents to register. -->
 <AgentConfiguration>
 <Type>Sitecore.Processing.Engine.Agents.TaskAgent, Sitecore.Processing.Engine</Type>
 <As>Sitecore.Processing.Engine.Abstractions.IAgent, Sitecore.Processing.Engine.Abstractions</As>
 <LifeTime>Transient</LifeTime>
 <Options>
 <!-- The period which the agent sleeps before running again. -->
 <SleepPeriod>0.\`00:00\`:14.000</SleepPeriod>
 <!-- The name of the machine on which the agent is running. -->
 <MachineName>${MachineName}</MachineName>
 </Options>
 </AgentConfiguration>
 </Options>
 </TaskAgents>
 </Services>
 </Processing>
 </Sitecore>
</Settings>

以下の設定はParallelAgentsConfigurationに特化しています:

舞台設定

概要

AgentFixedCount

登録すべきエージェントの絶対数を定義します。固定エージェントは AgentCoreRatioによって登録されたエージェントに加えて登録されます。

AgentCoreRatio

登録すべきエージェント数を、ホストマシン上の利用可能なコア数に対して AgentCoreRatio 個数の比率として定義します。8コアマシンの文脈では:  
  

-   比率が1なら8人のエージェントが登録されます。
-   比率が0.5の場合、4人のエージェントが登録されます。
-   比率が2なら16人のエージェントが登録されます。

  
  
ホストマシンをコア数で拡大すると、エージェントの数は自動的にスケールします。エージェントは AgentFixedCountによって登録されたエージェントに加えて登録されます。