SlideShare a Scribd company logo
1 of 28
Download to read offline
How to speed up your
(API client) modules
Gonéri Le Bouder
Senior Software Engineer
Work with the Ansible Cloud team, with a focus on VMware technologies.
@goneri on GitHub
A bit about myself
2
Modules designed to interact with an API
1. Load Python and the extra dependencies
2. Open a session
3. Do the API call
4. Wrap the result and send it back to Ansible
API client modules
3
For every task, Ansible will
1. starts a new Python process on the target host
2. send the module and run it on target host
3. collect the result
How Ansible works
4
Python start-up time is pretty good
$ time python -c "print('some Python')"
some Python
real 0m0.029s
user 0m0.023s
sys 0m0.006s
A new Python process per task
5
VMware
$ time python -c "from pyVmomi import vim; print('some Python')"
some Python
real 0m0.138s
user 0m0.122s
sys 0m0.016s
But the modules import can slow it down
6
Azure
$ time python -c "from azure.mgmt.compute import
ComputeManagementClient; from azure.mgmt.rdbms.mariadb import
MariaDBManagementClient; print('some Python')"
some Python
real 0m0.218s
user 0m0.195s
sys 0m0.021s
But the modules import can slow it down
7
OpenStack
$ time python -c "import openstack; print('some Python')"
some Python
real 0m0.444s
user 0m0.378s
sys 0m0.038s
But the modules import can slow it down
8
Each time a task runs, a Python process import the dependencies
● Only load the subset of dependencies that you really need
● Be cautious when you add a new import
Module loading
9
Before anything, the module need to open a session and authenticate
itself
● ping will matter, e.g: if you're API endpoint is 200ms away
● the authentication itself may be slow because of the backend (e.g:
LDAP or AD)
Session opening
10
Ansible Module
Turbo
How to speed up your modules start-up
11
Concept
Give a way to reuse your Python objects, between tasks execution.
● libraries are loaded just once
● reuse the existing session
Ansible Module Turbo
12
13
Prepare your
environment
Ansible Module Turbo is part of the cloud.common collection
ansible-galaxy collection install cloud.common
Fetch the new dependency
14
Add a dependency on the cloud.common collection in galaxy.yml
namespace: vmware
name: vmware_rest
readme: README.md
authors:
- Ansible (https://github.com/ansible)
description:
license_file: LICENSE
tags: ["cloud", "vmware", "virtualization"]
dependencies:
cloud.common: '*'
Adjust your collection metadata
15
turbo.demo is a demo module for the ansible_module.turbo. Use it to validate
your installation:
- hosts: localhost
gather_facts: false
tasks:
- cloud.common.turbo_demo:
with_sequence: count=10
Good enough for a first test run (1/2)
16
During the playbook execution
● the Python keeps the same PID
● the counter is increased after every execution
When the playbook is restarted
● it still runs with the same PID
● the counter continue to increase
https://asciinema.org/a/358962
Good enough for a first test run (2/2)
17
An example with the os_keypair module, the playbook runs the module 6 times.
● first time is slow >3s
● next 5 calls are below 0.6s
https://asciinema.org/a/345197
Example
18
19
Adjust your module
And adjust your modules, to load the alternative AnsibleModule
from ansible.module_utils.basic import AnsibleModule
from
ansible_collections.cloud.common.plugins.module_utils.turb
o.module import AnsibleTurboModule as AnsibleModule
Tune up your module (1/3)
20
Identify where to add a cache
For instance, this function returns a new client:
import MySDK
def my_slow_function():
return my_sdk.Client()
Tune up your module (2/3)
21
You can cache a function result with a simple Python construction:
def my_slow_function():
if my_slow_function.i:
return my_slow_function.i❶
my_sdk = importlib.import_module("MySDK")❷
my_slow_function.i = my_sdk.Client()❸
return my_slow_function.i
my_slow_function.i = None❹
note: You can also use a library like async_lru.
Tune up your module (3/3)
22
1. install cloud.common
2. load AnsibleTurboModule instead of AnsibleModule
3. delay the import
4. cache the session
To summarize
23
24
Under the hood
Ansible Module Turbo starts a local process and delegate all the operation to it.
It uses Python's asyncio internally:
● Python 3.6+
● you can also use asyncio coroutine in your module
The daemon kills itself after 15s with no activity.
How it works?
25
Conclusion
26
Good way to speed up your module if
● it depends on a large SDK
● the initial session creation is slow
Easy to switch to Ansible Module Turbo
● limited amount of code to adjust
● keep in minds it depends on Python3.6
27
Red Hat is the world’s leading provider of enterprise
open source software solutions. Award-winning
support, training, and consulting services make
Red Hat a trusted adviser to the Fortune 500.
Thank you
youtube.com/user/RedHatVideos linkedin.com/company/Red-Hat
facebook.com/ansibleautomation twitter.com/ansible

More Related Content

What's hot

Hybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitHybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitVijayananda Mohire
 
Fun with containers: Use Ansible to build Docker images
Fun with containers: Use Ansible to build Docker imagesFun with containers: Use Ansible to build Docker images
Fun with containers: Use Ansible to build Docker imagesabadger1999
 
Managing Your Cisco Datacenter Network with Ansible
Managing Your Cisco Datacenter Network with AnsibleManaging Your Cisco Datacenter Network with Ansible
Managing Your Cisco Datacenter Network with Ansiblefmaccioni
 
Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesLarry Cai
 
Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Dan Kuebrich
 
(APP310) Scheduling Using Apache Mesos in the Cloud | AWS re:Invent 2014
(APP310) Scheduling Using Apache Mesos in the Cloud | AWS re:Invent 2014(APP310) Scheduling Using Apache Mesos in the Cloud | AWS re:Invent 2014
(APP310) Scheduling Using Apache Mesos in the Cloud | AWS re:Invent 2014Amazon Web Services
 
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
Ansible 2.0 - How to use Ansible to automate your applications in AWS.Ansible 2.0 - How to use Ansible to automate your applications in AWS.
Ansible 2.0 - How to use Ansible to automate your applications in AWS.Idan Tohami
 
Azure Quantum with IBM Qiskit and IonQ QPU
Azure Quantum with IBM Qiskit and IonQ QPUAzure Quantum with IBM Qiskit and IonQ QPU
Azure Quantum with IBM Qiskit and IonQ QPUVijayananda Mohire
 
Integrating cloud stack with puppet
Integrating cloud stack with puppetIntegrating cloud stack with puppet
Integrating cloud stack with puppetPuppet
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsGraham Dumpleton
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the CloudWesley Beary
 
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
Introduction to Packer and Suitcase: A Packer-based OS Image Build SystemIntroduction to Packer and Suitcase: A Packer-based OS Image Build System
Introduction to Packer and Suitcase: A Packer-based OS Image Build SystemHubSpot Product Team
 
Managing Puppet using MCollective
Managing Puppet using MCollectiveManaging Puppet using MCollective
Managing Puppet using MCollectivePuppet
 
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeAcademy
 
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'rmcleay
 

What's hot (20)

Hybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskitHybrid quantum classical neural networks with pytorch and qiskit
Hybrid quantum classical neural networks with pytorch and qiskit
 
Fun with containers: Use Ansible to build Docker images
Fun with containers: Use Ansible to build Docker imagesFun with containers: Use Ansible to build Docker images
Fun with containers: Use Ansible to build Docker images
 
Managing Your Cisco Datacenter Network with Ansible
Managing Your Cisco Datacenter Network with AnsibleManaging Your Cisco Datacenter Network with Ansible
Managing Your Cisco Datacenter Network with Ansible
 
Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutes
 
Cyansible
CyansibleCyansible
Cyansible
 
Ansible container
Ansible containerAnsible container
Ansible container
 
Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012Python Load Testing - Pygotham 2012
Python Load Testing - Pygotham 2012
 
Ansible 2.2
Ansible 2.2Ansible 2.2
Ansible 2.2
 
(APP310) Scheduling Using Apache Mesos in the Cloud | AWS re:Invent 2014
(APP310) Scheduling Using Apache Mesos in the Cloud | AWS re:Invent 2014(APP310) Scheduling Using Apache Mesos in the Cloud | AWS re:Invent 2014
(APP310) Scheduling Using Apache Mesos in the Cloud | AWS re:Invent 2014
 
Docker Birtday #5
Docker Birtday #5Docker Birtday #5
Docker Birtday #5
 
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
Ansible 2.0 - How to use Ansible to automate your applications in AWS.Ansible 2.0 - How to use Ansible to automate your applications in AWS.
Ansible 2.0 - How to use Ansible to automate your applications in AWS.
 
Azure Quantum with IBM Qiskit and IonQ QPU
Azure Quantum with IBM Qiskit and IonQ QPUAzure Quantum with IBM Qiskit and IonQ QPU
Azure Quantum with IBM Qiskit and IonQ QPU
 
Integrating cloud stack with puppet
Integrating cloud stack with puppetIntegrating cloud stack with puppet
Integrating cloud stack with puppet
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
Ansible testing
Ansible   testingAnsible   testing
Ansible testing
 
fog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloudfog or: How I Learned to Stop Worrying and Love the Cloud
fog or: How I Learned to Stop Worrying and Love the Cloud
 
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
Introduction to Packer and Suitcase: A Packer-based OS Image Build SystemIntroduction to Packer and Suitcase: A Packer-based OS Image Build System
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
 
Managing Puppet using MCollective
Managing Puppet using MCollectiveManaging Puppet using MCollective
Managing Puppet using MCollective
 
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With KubernetesKubeCon EU 2016: Getting the Jobs Done With Kubernetes
KubeCon EU 2016: Getting the Jobs Done With Kubernetes
 
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
DevOps in a Regulated World - aka 'Ansible, AWS, and Jenkins'
 

Similar to How to speed up your (API client) modules

Setting up a kubernetes cluster on ubuntu 18.04- loves cloud
Setting up a kubernetes cluster on ubuntu 18.04- loves cloudSetting up a kubernetes cluster on ubuntu 18.04- loves cloud
Setting up a kubernetes cluster on ubuntu 18.04- loves cloudLoves Cloud
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and ContainersRodolfo Carvalho
 
Ansible Workshop for Pythonistas
Ansible Workshop for PythonistasAnsible Workshop for Pythonistas
Ansible Workshop for PythonistasMihai Criveti
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS MeetupLINAGORA
 
Kubernetes laravel and kubernetes
Kubernetes   laravel and kubernetesKubernetes   laravel and kubernetes
Kubernetes laravel and kubernetesWilliam Stewart
 
Ansible Automation Inside Cloudforms ( Embedded Ansible)
Ansible Automation Inside Cloudforms ( Embedded Ansible)Ansible Automation Inside Cloudforms ( Embedded Ansible)
Ansible Automation Inside Cloudforms ( Embedded Ansible)Prasad Mukhedkar
 
Okd wg kubecon marathon azure & vsphere
Okd wg kubecon marathon azure & vsphereOkd wg kubecon marathon azure & vsphere
Okd wg kubecon marathon azure & vsphereWalid Shaari
 
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...Puppet
 
Baking docker using chef
Baking docker using chefBaking docker using chef
Baking docker using chefMukta Aphale
 
Baking Docker Using Chef - ChefConf 2015
Baking Docker Using Chef - ChefConf 2015Baking Docker Using Chef - ChefConf 2015
Baking Docker Using Chef - ChefConf 2015Chef
 
Docker Basic to Advance
Docker Basic to AdvanceDocker Basic to Advance
Docker Basic to AdvanceParas Jain
 
Scaling docker with kubernetes
Scaling docker with kubernetesScaling docker with kubernetes
Scaling docker with kubernetesLiran Cohen
 
K8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals TrainingK8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals TrainingPiotr Perzyna
 
Deploy Mediawiki Using FIWARE Lab Facilities
Deploy Mediawiki Using FIWARE Lab FacilitiesDeploy Mediawiki Using FIWARE Lab Facilities
Deploy Mediawiki Using FIWARE Lab FacilitiesFIWARE
 
CloudStack and cloud-init
CloudStack and cloud-initCloudStack and cloud-init
CloudStack and cloud-initMarcusS13
 
Improving the Accumulo User Experience
 Improving the Accumulo User Experience Improving the Accumulo User Experience
Improving the Accumulo User ExperienceAccumulo Summit
 

Similar to How to speed up your (API client) modules (20)

Setting up a kubernetes cluster on ubuntu 18.04- loves cloud
Setting up a kubernetes cluster on ubuntu 18.04- loves cloudSetting up a kubernetes cluster on ubuntu 18.04- loves cloud
Setting up a kubernetes cluster on ubuntu 18.04- loves cloud
 
Mihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate EverythingMihai Criveti - PyCon Ireland - Automate Everything
Mihai Criveti - PyCon Ireland - Automate Everything
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Ansible Workshop for Pythonistas
Ansible Workshop for PythonistasAnsible Workshop for Pythonistas
Ansible Workshop for Pythonistas
 
One-Man Ops
One-Man OpsOne-Man Ops
One-Man Ops
 
Advanced Node.JS Meetup
Advanced Node.JS MeetupAdvanced Node.JS Meetup
Advanced Node.JS Meetup
 
Kubernetes laravel and kubernetes
Kubernetes   laravel and kubernetesKubernetes   laravel and kubernetes
Kubernetes laravel and kubernetes
 
Ansible Automation Inside Cloudforms ( Embedded Ansible)
Ansible Automation Inside Cloudforms ( Embedded Ansible)Ansible Automation Inside Cloudforms ( Embedded Ansible)
Ansible Automation Inside Cloudforms ( Embedded Ansible)
 
Okd wg kubecon marathon azure & vsphere
Okd wg kubecon marathon azure & vsphereOkd wg kubecon marathon azure & vsphere
Okd wg kubecon marathon azure & vsphere
 
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
 
Baking docker using chef
Baking docker using chefBaking docker using chef
Baking docker using chef
 
Baking Docker Using Chef - ChefConf 2015
Baking Docker Using Chef - ChefConf 2015Baking Docker Using Chef - ChefConf 2015
Baking Docker Using Chef - ChefConf 2015
 
Docker Basic to Advance
Docker Basic to AdvanceDocker Basic to Advance
Docker Basic to Advance
 
Scaling docker with kubernetes
Scaling docker with kubernetesScaling docker with kubernetes
Scaling docker with kubernetes
 
K8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals TrainingK8s in 3h - Kubernetes Fundamentals Training
K8s in 3h - Kubernetes Fundamentals Training
 
Deploy Mediawiki Using FIWARE Lab Facilities
Deploy Mediawiki Using FIWARE Lab FacilitiesDeploy Mediawiki Using FIWARE Lab Facilities
Deploy Mediawiki Using FIWARE Lab Facilities
 
CloudStack and cloud-init
CloudStack and cloud-initCloudStack and cloud-init
CloudStack and cloud-init
 
Improving the Accumulo User Experience
 Improving the Accumulo User Experience Improving the Accumulo User Experience
Improving the Accumulo User Experience
 
Deploy MediaWiki usgin Fiware Lab Facilities
Deploy MediaWiki usgin Fiware Lab FacilitiesDeploy MediaWiki usgin Fiware Lab Facilities
Deploy MediaWiki usgin Fiware Lab Facilities
 
Open Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFVOpen Dayligth usando SDN-NFV
Open Dayligth usando SDN-NFV
 

More from Gonéri Le Bouder

Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdf
Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdfRed Hat Ansible Lightspeed Ansible Meetup-2023-11.pdf
Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdfGonéri Le Bouder
 
Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02Gonéri Le Bouder
 
Ansible meetup - Québec - april 25th, 2019
Ansible meetup - Québec - april 25th, 2019Ansible meetup - Québec - april 25th, 2019
Ansible meetup - Québec - april 25th, 2019Gonéri Le Bouder
 
Montreal ansible meetup april 17th, 2019
Montreal ansible meetup   april 17th, 2019Montreal ansible meetup   april 17th, 2019
Montreal ansible meetup april 17th, 2019Gonéri Le Bouder
 
How to driver your webservices with ansible
How to driver your webservices with ansibleHow to driver your webservices with ansible
How to driver your webservices with ansibleGonéri Le Bouder
 
Distributed-CI - OpenStack Montréal - 2018-06
Distributed-CI - OpenStack Montréal - 2018-06Distributed-CI - OpenStack Montréal - 2018-06
Distributed-CI - OpenStack Montréal - 2018-06Gonéri Le Bouder
 
DCI presentation during OpenStack Montréal - 2018-06
DCI presentation during OpenStack Montréal - 2018-06DCI presentation during OpenStack Montréal - 2018-06
DCI presentation during OpenStack Montréal - 2018-06Gonéri Le Bouder
 
How to use TripleO tools for your own project
How to use TripleO tools for your own projectHow to use TripleO tools for your own project
How to use TripleO tools for your own projectGonéri Le Bouder
 
Fusioninventory journees-perl-2012
Fusioninventory journees-perl-2012Fusioninventory journees-perl-2012
Fusioninventory journees-perl-2012Gonéri Le Bouder
 
Otrs help desk-solutions-linux-2012
Otrs help desk-solutions-linux-2012Otrs help desk-solutions-linux-2012
Otrs help desk-solutions-linux-2012Gonéri Le Bouder
 
Fusioninventory openworldforum-paris-2011-september
Fusioninventory openworldforum-paris-2011-septemberFusioninventory openworldforum-paris-2011-september
Fusioninventory openworldforum-paris-2011-septemberGonéri Le Bouder
 
Linuxtag 2011-it-asset-management-glpi-fusioninventory
Linuxtag 2011-it-asset-management-glpi-fusioninventoryLinuxtag 2011-it-asset-management-glpi-fusioninventory
Linuxtag 2011-it-asset-management-glpi-fusioninventoryGonéri Le Bouder
 
High Performance Computing and Open Source & Linux Technical Excellence Sympo...
High Performance Computing and Open Source & Linux Technical Excellence Sympo...High Performance Computing and Open Source & Linux Technical Excellence Sympo...
High Performance Computing and Open Source & Linux Technical Excellence Sympo...Gonéri Le Bouder
 
Fusioninventory project FOSDEM 2011
Fusioninventory project FOSDEM 2011Fusioninventory project FOSDEM 2011
Fusioninventory project FOSDEM 2011Gonéri Le Bouder
 
Fusioninventory froscamp2010
Fusioninventory froscamp2010Fusioninventory froscamp2010
Fusioninventory froscamp2010Gonéri Le Bouder
 

More from Gonéri Le Bouder (20)

Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdf
Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdfRed Hat Ansible Lightspeed Ansible Meetup-2023-11.pdf
Red Hat Ansible Lightspeed Ansible Meetup-2023-11.pdf
 
Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02Virt lightning-montreal-linux-meetup-2020-02
Virt lightning-montreal-linux-meetup-2020-02
 
Ansible meetup - Québec - april 25th, 2019
Ansible meetup - Québec - april 25th, 2019Ansible meetup - Québec - april 25th, 2019
Ansible meetup - Québec - april 25th, 2019
 
Montreal ansible meetup april 17th, 2019
Montreal ansible meetup   april 17th, 2019Montreal ansible meetup   april 17th, 2019
Montreal ansible meetup april 17th, 2019
 
How to driver your webservices with ansible
How to driver your webservices with ansibleHow to driver your webservices with ansible
How to driver your webservices with ansible
 
Distributed-CI - OpenStack Montréal - 2018-06
Distributed-CI - OpenStack Montréal - 2018-06Distributed-CI - OpenStack Montréal - 2018-06
Distributed-CI - OpenStack Montréal - 2018-06
 
DCI presentation during OpenStack Montréal - 2018-06
DCI presentation during OpenStack Montréal - 2018-06DCI presentation during OpenStack Montréal - 2018-06
DCI presentation during OpenStack Montréal - 2018-06
 
Python + ansible = ♥
Python + ansible = ♥Python + ansible = ♥
Python + ansible = ♥
 
How to use TripleO tools for your own project
How to use TripleO tools for your own projectHow to use TripleO tools for your own project
How to use TripleO tools for your own project
 
Fusioninventory journees-perl-2012
Fusioninventory journees-perl-2012Fusioninventory journees-perl-2012
Fusioninventory journees-perl-2012
 
Otrs help desk-solutions-linux-2012
Otrs help desk-solutions-linux-2012Otrs help desk-solutions-linux-2012
Otrs help desk-solutions-linux-2012
 
Fusioninventory openworldforum-paris-2011-september
Fusioninventory openworldforum-paris-2011-septemberFusioninventory openworldforum-paris-2011-september
Fusioninventory openworldforum-paris-2011-september
 
GLPI RMLL-2011
GLPI RMLL-2011GLPI RMLL-2011
GLPI RMLL-2011
 
Fusioninventory rmll-2011
Fusioninventory rmll-2011Fusioninventory rmll-2011
Fusioninventory rmll-2011
 
Linuxtag 2011-it-asset-management-glpi-fusioninventory
Linuxtag 2011-it-asset-management-glpi-fusioninventoryLinuxtag 2011-it-asset-management-glpi-fusioninventory
Linuxtag 2011-it-asset-management-glpi-fusioninventory
 
High Performance Computing and Open Source & Linux Technical Excellence Sympo...
High Performance Computing and Open Source & Linux Technical Excellence Sympo...High Performance Computing and Open Source & Linux Technical Excellence Sympo...
High Performance Computing and Open Source & Linux Technical Excellence Sympo...
 
Fusioninventory project FOSDEM 2011
Fusioninventory project FOSDEM 2011Fusioninventory project FOSDEM 2011
Fusioninventory project FOSDEM 2011
 
Fusioninventory 2010-french
Fusioninventory 2010-frenchFusioninventory 2010-french
Fusioninventory 2010-french
 
Fusioninventory froscamp2010
Fusioninventory froscamp2010Fusioninventory froscamp2010
Fusioninventory froscamp2010
 
présentation de Debian 2
présentation de Debian 2présentation de Debian 2
présentation de Debian 2
 

Recently uploaded

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 

Recently uploaded (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 

How to speed up your (API client) modules

  • 1. How to speed up your (API client) modules Gonéri Le Bouder Senior Software Engineer
  • 2. Work with the Ansible Cloud team, with a focus on VMware technologies. @goneri on GitHub A bit about myself 2
  • 3. Modules designed to interact with an API 1. Load Python and the extra dependencies 2. Open a session 3. Do the API call 4. Wrap the result and send it back to Ansible API client modules 3
  • 4. For every task, Ansible will 1. starts a new Python process on the target host 2. send the module and run it on target host 3. collect the result How Ansible works 4
  • 5. Python start-up time is pretty good $ time python -c "print('some Python')" some Python real 0m0.029s user 0m0.023s sys 0m0.006s A new Python process per task 5
  • 6. VMware $ time python -c "from pyVmomi import vim; print('some Python')" some Python real 0m0.138s user 0m0.122s sys 0m0.016s But the modules import can slow it down 6
  • 7. Azure $ time python -c "from azure.mgmt.compute import ComputeManagementClient; from azure.mgmt.rdbms.mariadb import MariaDBManagementClient; print('some Python')" some Python real 0m0.218s user 0m0.195s sys 0m0.021s But the modules import can slow it down 7
  • 8. OpenStack $ time python -c "import openstack; print('some Python')" some Python real 0m0.444s user 0m0.378s sys 0m0.038s But the modules import can slow it down 8
  • 9. Each time a task runs, a Python process import the dependencies ● Only load the subset of dependencies that you really need ● Be cautious when you add a new import Module loading 9
  • 10. Before anything, the module need to open a session and authenticate itself ● ping will matter, e.g: if you're API endpoint is 200ms away ● the authentication itself may be slow because of the backend (e.g: LDAP or AD) Session opening 10
  • 11. Ansible Module Turbo How to speed up your modules start-up 11
  • 12. Concept Give a way to reuse your Python objects, between tasks execution. ● libraries are loaded just once ● reuse the existing session Ansible Module Turbo 12
  • 14. Ansible Module Turbo is part of the cloud.common collection ansible-galaxy collection install cloud.common Fetch the new dependency 14
  • 15. Add a dependency on the cloud.common collection in galaxy.yml namespace: vmware name: vmware_rest readme: README.md authors: - Ansible (https://github.com/ansible) description: license_file: LICENSE tags: ["cloud", "vmware", "virtualization"] dependencies: cloud.common: '*' Adjust your collection metadata 15
  • 16. turbo.demo is a demo module for the ansible_module.turbo. Use it to validate your installation: - hosts: localhost gather_facts: false tasks: - cloud.common.turbo_demo: with_sequence: count=10 Good enough for a first test run (1/2) 16
  • 17. During the playbook execution ● the Python keeps the same PID ● the counter is increased after every execution When the playbook is restarted ● it still runs with the same PID ● the counter continue to increase https://asciinema.org/a/358962 Good enough for a first test run (2/2) 17
  • 18. An example with the os_keypair module, the playbook runs the module 6 times. ● first time is slow >3s ● next 5 calls are below 0.6s https://asciinema.org/a/345197 Example 18
  • 20. And adjust your modules, to load the alternative AnsibleModule from ansible.module_utils.basic import AnsibleModule from ansible_collections.cloud.common.plugins.module_utils.turb o.module import AnsibleTurboModule as AnsibleModule Tune up your module (1/3) 20
  • 21. Identify where to add a cache For instance, this function returns a new client: import MySDK def my_slow_function(): return my_sdk.Client() Tune up your module (2/3) 21
  • 22. You can cache a function result with a simple Python construction: def my_slow_function(): if my_slow_function.i: return my_slow_function.i❶ my_sdk = importlib.import_module("MySDK")❷ my_slow_function.i = my_sdk.Client()❸ return my_slow_function.i my_slow_function.i = None❹ note: You can also use a library like async_lru. Tune up your module (3/3) 22
  • 23. 1. install cloud.common 2. load AnsibleTurboModule instead of AnsibleModule 3. delay the import 4. cache the session To summarize 23
  • 25. Ansible Module Turbo starts a local process and delegate all the operation to it. It uses Python's asyncio internally: ● Python 3.6+ ● you can also use asyncio coroutine in your module The daemon kills itself after 15s with no activity. How it works? 25
  • 27. Good way to speed up your module if ● it depends on a large SDK ● the initial session creation is slow Easy to switch to Ansible Module Turbo ● limited amount of code to adjust ● keep in minds it depends on Python3.6 27
  • 28. Red Hat is the world’s leading provider of enterprise open source software solutions. Award-winning support, training, and consulting services make Red Hat a trusted adviser to the Fortune 500. Thank you youtube.com/user/RedHatVideos linkedin.com/company/Red-Hat facebook.com/ansibleautomation twitter.com/ansible