Skip to content

Throttling activity

Gurmit Teotia edited this page Nov 29, 2017 · 6 revisions

Guflow allows you control the number of activity tasks executing concurrently in a host. By default ActivititesHost executes the activity tasks concurrently equal to the number of processor's core. You can change the activity concurrency level as shown below:

using(var host = domain.Host(new []{typeof(Activity1)}))
{
  //Below code will allow 10 activity tasks to be executed concurrently on this host.
  host.Execution = ActivityExecution.Concurrent(10);
  host.StartExecution()
  Console.WriteLine("Press any key to terminate");
  Console.ReadKey();
}  

The number of threads used to execute activity tasks concurrently depends on how you are writing the activity execute method. For synchronous activity method one thread will be used to execute a activity task which means in above example 10 threads will be used to execute 10 activity tasks. However if the activity execution method is async then number of threads used to execute 10 activity task concurrently will be lower.

You can also configure the ActivityHost to execute only one activity task at a time as show below:

```cs
using(var host = domain.Host(new []{typeof(Activity1)}))
{
  //Following code will configure the host to execute the activity task in 
  host.Execution = ActivityExecution.Sequential;
  host.StartExecution();
  Console.WriteLine("Press any key to terminate");
  Console.ReadKey();
}  

Clone this wiki locally