{"id":1137,"date":"2019-07-02T16:27:00","date_gmt":"2019-07-02T10:57:00","guid":{"rendered":"http:\/\/blogs.opstree.com\/?p=1137"},"modified":"2019-08-27T16:29:29","modified_gmt":"2019-08-27T10:59:29","slug":"speeding-up-ansible-execution-part-2","status":"publish","type":"post","link":"https:\/\/opstree.com\/blog\/2019\/07\/02\/speeding-up-ansible-execution-part-2\/","title":{"rendered":"Speeding up Ansible Execution Part 2"},"content":{"rendered":"\n<p>     <strong> MITOGEN<\/strong><\/p>\n\n\n\n<p><br> In the previous post, we discussed various ways to reduce the ansible-playbook execution time, those changes were mostly made in the ansible config file, by adding or adjusting certain parameters in the file. But as you may have noticed that those methods were not that effective in certain cases, while using those methods we have to be very cautious about the result as they may affect ansible performance in one way or the other.<\/p>\n\n\n\n<p><br>\nGenerally,\n for the slower ansible execution, the main culprit is the way ansible \nis executed on the hosts. It creates multiple SSH connections and does \nnot fully utilize the available resources. To tackle this problem, \nMITOGEN came to rescue !!!<\/p>\n\n\n\n<p>Mitogen&nbsp;is a distributed programming library for Python.\nThe&nbsp;Mitogen&nbsp;extension&nbsp;is a set of plug-ins for Ansible that enable it to operate via Mitogen,\nvastly improving its performance and enhancing its functional capability.<\/p>\n\n\n\n<p>We\nall know about the strategies in ansible \u2013 linear, free &amp; debug., the mitogen\nis just defined in the strategy column of the config file, so it is just a\nstrategy, we are not making any other changes in the config file of the ansible\nso it is not affecting any other parameter, it is just the way, playbooks will\nbe executed on the hosts.<\/p>\n\n\n\n<p>Now coming to the mitogen installation part, we just have to\ndownload&nbsp;<a href=\"https:\/\/networkgenomics.com\/try\/mitogen-0.2.7.tar.gz\" target=\"_blank\" rel=\"noopener\">this<\/a><a href=\"https:\/\/networkgenomics.com\/try\/mitogen-0.2.7.tar.gz\" target=\"_blank\" rel=\"noopener\">&nbsp;package<\/a>&nbsp;at a particular\nlocation and make some changes in the ansible config file as shown below,<\/p>\n\n\n\n<p><strong>[defaults]<\/strong><\/p>\n\n\n\n<p><strong>strategy_plugins = \/path\/to\/mitogen\/ansible_mitogen\/plugins\/strategystrategy = mitogen_linear<\/strong><\/p>\n\n\n\n<p>we\nhave to define the path where we have stored our mitogen files, and mention the\nstrategy as \u201cmitogen_linear\u201d, under the default section of the config file, and\nwe are good to go.<\/p>\n\n\n\n<p>Now, after the Mitogen installation part, when we run our playbook, we will notice a reasonable reduction in the execution\ntime,<\/p>\n\n\n\n<p>Mitogen\nis fast because of the following reasons,<\/p>\n\n\n\n<ul><li>One connection is created per target and system logs\naren\u2019t spammed with repeated authentication events.<\/li><li>A\nsingle network roundtrip is used&nbsp;to execute a step whose code already\nexists in RAM on the target.<\/li><li>Processes\nare aggressively reused, avoiding the cost of invoking Python and recompiling\nimports, saving 300-800 ms for every playbook step.<\/li><li>Code\nis cached in the RAM, which further increases the speed.<\/li><li>Generally,\n ansible repeatedly rewrites and extracts ZIP files to temporary \ndirectories in the target hosts, mitogen also reduces these rewrites.<\/li><\/ul>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; All the above-mentioned features make\nthe ansible to run faster.<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; Mitogen is another extension for\nansible that provides a decrease in its execution time and it is very easy to\nuse, I think&nbsp;<strong>MITOGEN<\/strong>&nbsp;is\nvery underrated and one of its kind, and we should definitely give it a try.<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; I hope I have explained\neverything well, any suggestion\/queries are highly appreciated.<\/p>\n\n\n\n<p><br>\nThanks !!!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\nSource:<\/h3>\n\n\n\n<p>https:\/\/mitogen.networkgenomics.com\/ansible_detailed.html<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MITOGEN In the previous post, we discussed various ways to reduce the ansible-playbook execution time, those changes were mostly made in the ansible config file, by adding or adjusting certain parameters in the file. But as you may have noticed that those methods were not that effective in certain cases, while using those methods we &hellip; <a href=\"https:\/\/opstree.com\/blog\/2019\/07\/02\/speeding-up-ansible-execution-part-2\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Speeding up Ansible Execution Part 2&#8221;<\/span><\/a><\/p>\n","protected":false},"author":159857009,"featured_media":29900,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[768739304,768739308,78903641],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/opstree.com\/blog\/wp-content\/uploads\/2025\/11\/DevSecOps-1.jpg","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pfDBOm-il","jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/1137"}],"collection":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/users\/159857009"}],"replies":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/comments?post=1137"}],"version-history":[{"count":9,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/1137\/revisions"}],"predecessor-version":[{"id":1170,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/posts\/1137\/revisions\/1170"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media\/29900"}],"wp:attachment":[{"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/media?parent=1137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/categories?post=1137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/opstree.com\/blog\/wp-json\/wp\/v2\/tags?post=1137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}