{"id":3325,"date":"2012-10-23T14:28:43","date_gmt":"2012-10-23T12:28:43","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=3325"},"modified":"2012-10-23T14:28:43","modified_gmt":"2012-10-23T12:28:43","slug":"job-concurrency-in-orchestrator","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=3325","title":{"rendered":"Job Concurrency in Orchestrator"},"content":{"rendered":"<p>At each runbook you can configure Job\u00c2\u00a0Concurrency, default setting is &#8220;1&#8221;.\u00c2\u00a0The job concurrency setting lets you configure the maximum number of simultaneous jobs, for an individual runbook, so that you can carry out multiple requests for the same runbook at the same time. With the default setting of &#8220;1&#8221; only one instance of the runbook will run at the same time.<\/p>\n<p>There are some scenario where you need to modify this setting, also a couple of scenario where you should not modify it. For example if you have a runbook working with a counter you should not have multiple runbooks instances running, as they will all affect the same counter. Another example are runbooks that starts with a Monitoring activity, they cannot run multiple instances. Before modifying this setting it is also important to look into what the runbook is doing, if the runbook for example creates a new unique computer name it sometimes will result with multiple computers with the same name.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue04.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3326\" title=\"20121023_queue04\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue04-300x201.jpg\" alt=\"\" width=\"300\" height=\"201\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue04-300x201.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue04.jpg 604w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I did a test with two runbooks, the first runbook trigger the second runbook. 5.1 trigger a new instance every 30 seconds, and invoke the 5.2 runbook. When 5.1 invoke runbook 5.2 it is also pass a timestamp to runbook 5.2. Runbook 5.2 writes the timestamp from runbook 5.1 and a new timestamp to a text file. Runbook 5.2 then sleeps for 3 minutes and ends.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue06.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3327\" title=\"20121023_queue06\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue06-300x297.jpg\" alt=\"\" width=\"300\" height=\"297\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue06-300x297.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue06-150x150.jpg 150w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue06.jpg 422w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue07.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3328\" title=\"20121023_queue07\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue07-300x213.jpg\" alt=\"\" width=\"300\" height=\"213\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue07-300x213.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue07.jpg 553w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>As runbook 5.1 trigger a new instance of runbook 5.2 every 30 seconds, and runbook 5.2 only runs one instances at the same time, there will be a queue. You can check the queue with the following SQL query against your Orchestrator database<\/p>\n<blockquote><p>SELECT [Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.Id, [Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.ParentId,<br \/>\n[Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.ParentIsWaiting, [Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.StatusId,<br \/>\n[Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.CreationTime, POLICIES.Name, DATEDIFF(MINUTE,<br \/>\n[Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.CreationTime, GETUTCDATE()) AS QueueTime<br \/>\nFROM [Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs INNER JOIN<br \/>\nPOLICIES ON [Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.RunbookId = POLICIES.UniqueID<br \/>\nWHERE ([Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.StatusId NOT LIKE &#8216;4&#8217;)<br \/>\nAND ([Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.StatusId NOT LIKE &#8216;3&#8217;)<br \/>\nAND ([Microsoft.SystemCenter.Orchestrator.Runtime.Internal].Jobs.StatusId NOT LIKE &#8216;2&#8217;)<\/p><\/blockquote>\n<p>This is a example of the result from the SQL query<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue03.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3331\" title=\"20121023_queue03\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue03-300x136.jpg\" alt=\"\" width=\"300\" height=\"136\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue03-300x136.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue03.jpg 941w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<ul>\n<li>ID is the runbook job instance ID<\/li>\n<li>ParentID is the job that started this job. As you can see in the image all jobs have a parentID that starts with 45723&#8230; that is the 5.1 runbook, the runbook with the Invoke Runbook activity<\/li>\n<li>ParentIsWaiting is set to &#8220;1&#8221; if the runbook that trigger this job is waiting until this job is complete. When you configure a Invoke Runbook activity there is &#8220;Wait to completion&#8221; option, if you check it the parent runbook will wait until the runbook it trigger is completed<\/li>\n<li>StatusId is current stats of the job.\n<ul>\n<li>0 = Pending<\/li>\n<li>1 = Running<\/li>\n<li>2 = Failed<\/li>\n<li>3 = Canceled<\/li>\n<li>4 = Completed<\/li>\n<\/ul>\n<\/li>\n<li>CreationTime is when the job was created in the database<\/li>\n<li>Name is the name of the runbook running<\/li>\n<li>QueueTime is number of minutes between &#8220;NOW&#8221; and CreationTime, number of minutes it has been in pending state<\/li>\n<\/ul>\n<p>Next image is an example of the log file that the 5.2 runbook writes to. As you can see the delay between the runbook was triggered and the time it executed is growing fast when only one runbook instance is allowed to run\u00c2\u00a0simultaneous.<\/p>\n<p><a href=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue02.jpg\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter size-medium wp-image-3333\" title=\"20121023_queue02\" src=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue02-300x57.jpg\" alt=\"\" width=\"300\" height=\"57\" srcset=\"http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue02-300x57.jpg 300w, http:\/\/contoso.se\/blog\/wp-content\/uploads\/2012\/10\/20121023_queue02.jpg 765w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At each runbook you can configure Job\u00c2\u00a0Concurrency, default setting is &#8220;1&#8221;.\u00c2\u00a0The job concurrency setting lets you configure the maximum number of simultaneous jobs, for an individual runbook, so that you can carry out multiple requests for the same runbook at the same time. With the default setting of &#8220;1&#8221; only one instance of the runbook &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=3325\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[60],"tags":[],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3325"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3325"}],"version-history":[{"count":6,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3325\/revisions"}],"predecessor-version":[{"id":3336,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3325\/revisions\/3336"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3325"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}