SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Micro	
  Army:	
  Load	
  Tes1ng	
  
                By	
  James	
  Dennis	
  (@j2labs)	
  
                               h?p://j2labs.net	
  
What	
  is	
  Micro	
  Army?	
  

•  Website	
  Load	
  Tes1ng	
  with	
  EC2	
  micros	
  
   –  Micros	
  are	
  cheap	
  
   –  I spent $2 building the tool
   –  Brubeck	
  vs.	
  Tornado	
  
         •  this	
  is	
  basically	
  Eventlet	
  vs.	
  Tornado	
  

   –  Easily	
  scalable,	
  	
  
         •  at	
  least	
  high	
  enough	
  to	
  slaughter	
  a	
  server	
  
Challenges	
  
•  Arbitrary	
  number	
  of	
  boxes	
  should	
  be	
  possible	
  
    – I	
  call	
  them	
  “cannons”	
  
    – They	
  should	
  be	
  configurable	
  via	
  some	
  script.	
  
        •  With	
  a	
  liAle	
  more	
  work,	
  it	
  could	
  be	
  an	
  admin	
  tool	
  

•  Parallel	
  
    – Deploying	
  the	
  cannons	
  must	
  be	
  parallel	
  
        •  I’m	
  impaEent	
  
    – The	
  cannons	
  must	
  fire	
  in	
  parallel	
  
Python	
  Modules	
  
•  Boto:	
  AWS	
  for	
  Python	
  
    – Used	
  to	
  deploy	
  EC2	
  instances	
  
•  Paramiko:	
  SSH	
  
    – Required	
  a	
  liAle	
  work	
  
    – Fairly	
  old	
  
         •  Not	
  sure	
  if	
  that’s	
  bad	
  though	
  
•  Eventlet:	
  paralleliza1on	
  (and	
  other	
  goodness)	
  
    – GreenPiles	
  are	
  easy	
  
    – Free	
  nonblocking	
  I/O	
  	
  
         •  Listen	
  up,	
  Tornado	
  users	
  
Using	
  It	
  
•  Deploy	
  
   – 	
  Hopefully	
  AWS	
  gives	
  us	
  our	
  boxes	
  
   – We’ll	
  need	
  a	
  list	
  of	
  hostnames	
  
   – SSH	
  to	
  each	
  host	
  and	
  setup	
  the	
  boxes	
  
        •  Upload	
  and	
  run	
  script	
  
        •  Must	
  be	
  parallel	
  or	
  large	
  numbers	
  hurts	
  
   – Prints	
  host	
  list	
  
        •  The	
  deploy	
  script	
  will	
  eval()	
  it	
  for	
  you!	
  
Using	
  It	
  
•  Firing	
  the	
  cannons	
  
    – SSH	
  to	
  all	
  boxes	
  and	
  run	
  `siege`	
  
         •  siege c 200 t 10s `hostname`
         •  I usually test with c 500
         •  Siege can handle GET and POST args (!)
    – Each	
  SSH	
  session	
  blocks	
  unEl	
  compleEon	
  
    – Eventlet	
  makes	
  this	
  easy	
  to	
  manage	
  
    – Quick	
  and	
  dirty	
  parsing	
  of	
  out	
  to	
  generate	
  a	
  CSV	
  
Show	
  Me	
  Code	
  
Micro	
  Army:	
  SeUngs	
  

       Easily	
  overrideable	
  with	
  local_seUngs.py	
  

### Create n instances
aws_access_key = ‘...'
aws_secret_key = ‘...'
ami_key = 'ami-ccf405a5’    # official ubuntu image
ec2_ssh_username = 'ubuntu' # ami specific
security_groups = [’MicroArmyGroup']
key_pair_name = ’micro_army_test'
num_cannons = 5
placement = 'us-east-1a’
instance_type = 't1.micro’
ec2_ssh_key = '/some/path/ec2_testing.pem'
Boto:	
  AWS	
  	
  
          Find	
  an	
  OS	
  image	
  (official	
  Ubuntu)	
  

import boto

# First, get a connection
ec2_conn = boto.connect_ec2(aws_access_key, aws_secret_key)

# Get *all* images that match this unique AMI key
images = ec2_conn.get_all_images(ami_key)
image = images[0]
Boto:	
  AWS	
  
             Instan1ate	
  N	
  boxes	
  

### Create n instances
r = image.run(min_count=num_cannons,
              max_count=num_cannons,
              placement=placement,
              security_groups=security_groups,
              key_name=key_pair_name,
              instance_type=instance_type)
Boto:	
  AWS	
  
         Launching	
  is	
  a	
  li?le	
  verbose…	
  

while True:
    # Give AWS some time to work
    time.sleep(5)

   # Aggregate our instance status info
   for i in r.instances:
       i.update()
   status = [i.state for i in r.instances]

   # Finish only if Amazon says all instances are up
   if status.count('running') == len(r.instances):
       print 'Done!’
       # Return list of host names
       return [i.public_dns_name for i in r.instances]
Paramiko:	
  SSH	
  
           Everything	
  you	
  need:	
  to	
  use	
  build	
  an	
  SSH	
  abstracEon	
  

jd@gibson : 14:42:44 : ~/Projects/microarmy/microarmy
$ wc -l communications.py

      61 communications.py

jd@gibson : 14:42:45 : ~/Projects/microarmy/microarmy
$ grep "def" communications.py

def ssh_connect(host, port=22):
def exec_command(transport, command, return_stderr=False):
# And half an SFTP abstraction...
def sftp_connect(transport):
def put_file(transport, local_path, remote_path):
def put_files(transport, paths):
Micro	
  Army:	
  build_cannon.sh	
  
               apt-­‐get	
  can	
  handle	
  everything	
  

 ### Let's get recent stuff

 apt-get update



 ### Install
 apt-get -y install 

         python-dev build-essential autoconf automake 

         libtool uuid-dev git-core mercurial python-pip 

         siege
Paramiko:	
  SSH	
  
                    Configure	
  each	
  cannon	
  with	
  a	
  script	
  

def _setup_a_cannon(hostname):
    # Get a connection (paramiko calls it a transport)
    ssh_conn = ssh_connect(hostname)

   # copy script to cannon and make it executable
   script_path = env_scripts_dir + '/' + CANNON_INIT_SCRIPT
   put_file(ssh_conn, script_path, CANNON_INIT_SCRIPT)
   response = exec_command(ssh_conn, 'chmod 755 ~/%s' % CANNON_INIT_SCRIPT)
   if response: # response would be error output
       return False

   # execute the setup script (expect this call to take a while)
   response = exec_command(ssh_conn, 'sudo ./%s' % CANNON_INIT_SCRIPT)
   return (hostname, response)
Eventlet:	
  GreenPools	
  
                       Setup	
  each	
  host	
  in	
  parallel	
  
def setup_cannons(hostnames):
    print 'Loading cannons... ',

   # Use eventlet’s abstraction of a collection of tasks: a GreenPile
   pile = eventlet.GreenPile(pool)

   # Spawn a coroutine in our pile for each host
   for hostname in hostnames:
       pile.spawn(_setup_a_cannon, hostname)

   # Iterating the pile causes eventlet to do the work
   responses = list(pile)

   return responses
Micro	
  Army:	
  Cannons	
  are	
  GO!	
  
   Time	
  to	
  blast	
  some	
  poor	
  web	
  server	
  (that	
  you	
  own)	
  
def fire_cannon(cannon_host, target):
    ssh_conn = ssh_connect(cannon_host)

   # 200 simultaneous connections requesting data for 10 seconds
   remote_command = 'siege -c200 -t10s %s' % (target)

   # Siege writes stats to stderr
   response = exec_command(ssh_conn,
                           remote_command,
                           return_stderr=True)
   return response
Micro	
  Army:	
  Fire	
  Cannons!	
  
    Same	
  strategy	
  as	
  before,	
  with	
  a	
  GreenPile	
  
def slam_host(cannon_hosts, target):
    # Familiar pattern
    pile = eventlet.GreenPile(pool)
    for hostname in cannon_hosts:
        pile.spawn(fire_cannon, hostname, target)
    responses = list(pile)

   # Parse output from each host for CSV generation
   report = parse_responses(responses)
   return report
Micro	
  Army:	
  Finishing	
  up.	
  
                   Just	
  the	
  facts,	
  micro.	
  

 Num_Trans,Elapsed,Tran_Rate	
  
 3679,	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  9.54,	
  	
  	
  	
  	
  	
  	
  385.64	
  
 3635,	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  9.48,	
  	
  	
  	
  	
  	
  	
  383.29	
  
 3535,	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  9.33,	
  	
  	
  	
  	
  	
  	
  378.89	
  
Micro	
  Army:	
  Recap	
  
                 • LAUNCH	
  some	
  number	
  of	
  EC2	
  micros	
  
                  	
  

                 • INSTALL	
  siege,	
  etc	
  on	
  instances	
  
                  	
  

                 • SLAM	
  web	
  host	
  from	
  micros	
  in	
  parallel	
  
                  	
  

                 • AGGREGATE	
  the	
  results	
  in	
  a	
  CSV	
  
                  	
  
Hopefully	
  you	
  learned	
  how	
  to…	
  
•  deploy	
  instances	
  on	
  EC2	
  with	
  Python	
  
•  execute	
  a	
  script	
  on	
  many	
  boxes	
  in	
  parallel	
  
•  use	
  SSH	
  from	
  Python	
  
    –  You	
  should	
  sEll	
  checkout	
  Fabric	
  (fabfile.org)	
  
•  use	
  the	
  excellent	
  module,	
  Eventlet:	
  
    – Free	
  nonblocking	
  I/O	
  
    – Simple,	
  but	
  efficient	
  concurrency	
  
    – Read	
  the	
  webpage,	
  it	
  actually	
  gets	
  beAer	
  
         •  Green	
  threads!	
  	
  
Try	
  it!	
  
   h?ps://github.com/j2labs/microarmy	
  

h?ps://console.aws.amazon.com/ec2/home	
  


           Read	
  more!	
  
           h?p://eventlet.net	
  
      h?p://www.lag.net/paramiko/	
  
      h?p://boto.cloudhackers.com/	
  
Ques1ons	
  



              ?	
  

James	
  Dennis	
  (@j2labs)	
  
  jdennis@gmail.com	
  

Weitere ähnliche Inhalte

Was ist angesagt?

GUIDE - Migrating AWS EBS backed AMI's between Regions
GUIDE - Migrating AWS EBS backed AMI's between RegionsGUIDE - Migrating AWS EBS backed AMI's between Regions
GUIDE - Migrating AWS EBS backed AMI's between Regions
Rob Linton
 

Was ist angesagt? (20)

Terraform Modules and Continuous Deployment
Terraform Modules and Continuous DeploymentTerraform Modules and Continuous Deployment
Terraform Modules and Continuous Deployment
 
Ansible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife OrchestrationAnsible - Swiss Army Knife Orchestration
Ansible - Swiss Army Knife Orchestration
 
Terraform Immutablish Infrastructure with Consul-Template
Terraform Immutablish Infrastructure with Consul-TemplateTerraform Immutablish Infrastructure with Consul-Template
Terraform Immutablish Infrastructure with Consul-Template
 
Capistrano, Puppet, and Chef
Capistrano, Puppet, and ChefCapistrano, Puppet, and Chef
Capistrano, Puppet, and Chef
 
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
 
DevOps with Fabric
DevOps with FabricDevOps with Fabric
DevOps with Fabric
 
GUIDE - Migrating AWS EBS backed AMI's between Regions
GUIDE - Migrating AWS EBS backed AMI's between RegionsGUIDE - Migrating AWS EBS backed AMI's between Regions
GUIDE - Migrating AWS EBS backed AMI's between Regions
 
Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017Terraform at Scale - All Day DevOps 2017
Terraform at Scale - All Day DevOps 2017
 
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECSAn intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
 
Infrastructure as Code with Terraform
Infrastructure as Code with TerraformInfrastructure as Code with Terraform
Infrastructure as Code with Terraform
 
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...
DevSecCon Asia 2017: Guillaume Dedrie: A trip through the securitiy of devops...
 
Ansible with AWS
Ansible with AWSAnsible with AWS
Ansible with AWS
 
Infrastructure as Code with Terraform
Infrastructure as Code with TerraformInfrastructure as Code with Terraform
Infrastructure as Code with Terraform
 
Fabric
FabricFabric
Fabric
 
infra-as-code
infra-as-codeinfra-as-code
infra-as-code
 
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine YardHow I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
How I Learned to Stop Worrying and Love the Cloud - Wesley Beary, Engine Yard
 
Reusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modules
 
Small Python Tools for Software Release Engineering
Small Python Tools for Software Release EngineeringSmall Python Tools for Software Release Engineering
Small Python Tools for Software Release Engineering
 
Scaling Ruby with Evented I/O - Ruby underground
Scaling Ruby with Evented I/O - Ruby undergroundScaling Ruby with Evented I/O - Ruby underground
Scaling Ruby with Evented I/O - Ruby underground
 
Setup 3 Node Kafka Cluster on AWS - Hands On
Setup 3 Node Kafka Cluster on AWS - Hands OnSetup 3 Node Kafka Cluster on AWS - Hands On
Setup 3 Node Kafka Cluster on AWS - Hands On
 

Andere mochten auch

ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
James Dennis
 

Andere mochten auch (9)

Brubeck
BrubeckBrubeck
Brubeck
 
Квартирный вопрос (3 рассказа для ознакомления)
Квартирный вопрос (3 рассказа для ознакомления)Квартирный вопрос (3 рассказа для ознакомления)
Квартирный вопрос (3 рассказа для ознакомления)
 
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)
Ведьмоспас. Евгений Лобачев (первые 4 главы для ознакомления)
 
Brubeck: The Lightning Talk
Brubeck: The Lightning TalkBrubeck: The Lightning Talk
Brubeck: The Lightning Talk
 
Brubeck: Overview
Brubeck: OverviewBrubeck: Overview
Brubeck: Overview
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika AldabaLightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
Lightning Talk #9: How UX and Data Storytelling Can Shape Policy by Mika Aldaba
 
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job? Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
Succession “Losers”: What Happens to Executives Passed Over for the CEO Job?
 

Ähnlich wie Microarmy - by J2 Labs

Controlling The Cloud With Python
Controlling The Cloud With PythonControlling The Cloud With Python
Controlling The Cloud With Python
Luca Mearelli
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
Simon McCartney
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
Wesley Beary
 

Ähnlich wie Microarmy - by J2 Labs (20)

Symfony finally swiped right on envvars
Symfony finally swiped right on envvarsSymfony finally swiped right on envvars
Symfony finally swiped right on envvars
 
Automation with Ansible and Containers
Automation with Ansible and ContainersAutomation with Ansible and Containers
Automation with Ansible and Containers
 
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGHDeploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
Deploying Docker (Provisioning /w Docker + Chef/Puppet) - DevopsDaysPGH
 
Testing Wi-Fi with OSS Tools
Testing Wi-Fi with OSS ToolsTesting Wi-Fi with OSS Tools
Testing Wi-Fi with OSS Tools
 
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
Service Delivery Assembly Line with Vagrant, Packer, and AnsibleService Delivery Assembly Line with Vagrant, Packer, and Ansible
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
 
R Jobs on the Cloud
R Jobs on the CloudR Jobs on the Cloud
R Jobs on the Cloud
 
Test driven infrastructure
Test driven infrastructureTest driven infrastructure
Test driven infrastructure
 
MySQL on AWS 101
MySQL on AWS 101MySQL on AWS 101
MySQL on AWS 101
 
Controlling The Cloud With Python
Controlling The Cloud With PythonControlling The Cloud With Python
Controlling The Cloud With Python
 
One-Man Ops
One-Man OpsOne-Man Ops
One-Man Ops
 
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010
 
Fullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-endFullstack conf 2017 - Basic dev pipeline end-to-end
Fullstack conf 2017 - Basic dev pipeline end-to-end
 
Julien Simon "Scaling ML from 0 to millions of users"
Julien Simon "Scaling ML from 0 to millions of users"Julien Simon "Scaling ML from 0 to millions of users"
Julien Simon "Scaling ML from 0 to millions of users"
 
Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013Stack kicker devopsdays-london-2013
Stack kicker devopsdays-london-2013
 
Ansible presentation
Ansible presentationAnsible presentation
Ansible presentation
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Testing Terraform
Testing TerraformTesting Terraform
Testing Terraform
 
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
fog or: How I Learned to Stop Worrying and Love the Cloud (OpenStack Edition)
 
Rust: Reach Further (from QCon Sao Paolo 2018)
Rust: Reach Further (from QCon Sao Paolo 2018)Rust: Reach Further (from QCon Sao Paolo 2018)
Rust: Reach Further (from QCon Sao Paolo 2018)
 
Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725Infrastructureascode slideshare-160331143725
Infrastructureascode slideshare-160331143725
 

Kürzlich hochgeladen

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Microarmy - by J2 Labs

  • 1. Micro  Army:  Load  Tes1ng   By  James  Dennis  (@j2labs)   h?p://j2labs.net  
  • 2. What  is  Micro  Army?   •  Website  Load  Tes1ng  with  EC2  micros   –  Micros  are  cheap   –  I spent $2 building the tool –  Brubeck  vs.  Tornado   •  this  is  basically  Eventlet  vs.  Tornado   –  Easily  scalable,     •  at  least  high  enough  to  slaughter  a  server  
  • 3. Challenges   •  Arbitrary  number  of  boxes  should  be  possible   – I  call  them  “cannons”   – They  should  be  configurable  via  some  script.   •  With  a  liAle  more  work,  it  could  be  an  admin  tool   •  Parallel   – Deploying  the  cannons  must  be  parallel   •  I’m  impaEent   – The  cannons  must  fire  in  parallel  
  • 4. Python  Modules   •  Boto:  AWS  for  Python   – Used  to  deploy  EC2  instances   •  Paramiko:  SSH   – Required  a  liAle  work   – Fairly  old   •  Not  sure  if  that’s  bad  though   •  Eventlet:  paralleliza1on  (and  other  goodness)   – GreenPiles  are  easy   – Free  nonblocking  I/O     •  Listen  up,  Tornado  users  
  • 5. Using  It   •  Deploy   –   Hopefully  AWS  gives  us  our  boxes   – We’ll  need  a  list  of  hostnames   – SSH  to  each  host  and  setup  the  boxes   •  Upload  and  run  script   •  Must  be  parallel  or  large  numbers  hurts   – Prints  host  list   •  The  deploy  script  will  eval()  it  for  you!  
  • 6. Using  It   •  Firing  the  cannons   – SSH  to  all  boxes  and  run  `siege`   •  siege c 200 t 10s `hostname` •  I usually test with c 500 •  Siege can handle GET and POST args (!) – Each  SSH  session  blocks  unEl  compleEon   – Eventlet  makes  this  easy  to  manage   – Quick  and  dirty  parsing  of  out  to  generate  a  CSV  
  • 8. Micro  Army:  SeUngs   Easily  overrideable  with  local_seUngs.py   ### Create n instances aws_access_key = ‘...' aws_secret_key = ‘...' ami_key = 'ami-ccf405a5’ # official ubuntu image ec2_ssh_username = 'ubuntu' # ami specific security_groups = [’MicroArmyGroup'] key_pair_name = ’micro_army_test' num_cannons = 5 placement = 'us-east-1a’ instance_type = 't1.micro’ ec2_ssh_key = '/some/path/ec2_testing.pem'
  • 9. Boto:  AWS     Find  an  OS  image  (official  Ubuntu)   import boto # First, get a connection ec2_conn = boto.connect_ec2(aws_access_key, aws_secret_key) # Get *all* images that match this unique AMI key images = ec2_conn.get_all_images(ami_key) image = images[0]
  • 10. Boto:  AWS   Instan1ate  N  boxes   ### Create n instances r = image.run(min_count=num_cannons, max_count=num_cannons, placement=placement, security_groups=security_groups, key_name=key_pair_name, instance_type=instance_type)
  • 11. Boto:  AWS   Launching  is  a  li?le  verbose…   while True: # Give AWS some time to work time.sleep(5) # Aggregate our instance status info for i in r.instances: i.update() status = [i.state for i in r.instances] # Finish only if Amazon says all instances are up if status.count('running') == len(r.instances): print 'Done!’ # Return list of host names return [i.public_dns_name for i in r.instances]
  • 12. Paramiko:  SSH   Everything  you  need:  to  use  build  an  SSH  abstracEon   jd@gibson : 14:42:44 : ~/Projects/microarmy/microarmy $ wc -l communications.py 61 communications.py jd@gibson : 14:42:45 : ~/Projects/microarmy/microarmy $ grep "def" communications.py def ssh_connect(host, port=22): def exec_command(transport, command, return_stderr=False): # And half an SFTP abstraction... def sftp_connect(transport): def put_file(transport, local_path, remote_path): def put_files(transport, paths):
  • 13. Micro  Army:  build_cannon.sh   apt-­‐get  can  handle  everything   ### Let's get recent stuff apt-get update ### Install apt-get -y install python-dev build-essential autoconf automake libtool uuid-dev git-core mercurial python-pip siege
  • 14. Paramiko:  SSH   Configure  each  cannon  with  a  script   def _setup_a_cannon(hostname): # Get a connection (paramiko calls it a transport) ssh_conn = ssh_connect(hostname) # copy script to cannon and make it executable script_path = env_scripts_dir + '/' + CANNON_INIT_SCRIPT put_file(ssh_conn, script_path, CANNON_INIT_SCRIPT) response = exec_command(ssh_conn, 'chmod 755 ~/%s' % CANNON_INIT_SCRIPT) if response: # response would be error output return False # execute the setup script (expect this call to take a while) response = exec_command(ssh_conn, 'sudo ./%s' % CANNON_INIT_SCRIPT) return (hostname, response)
  • 15. Eventlet:  GreenPools   Setup  each  host  in  parallel   def setup_cannons(hostnames): print 'Loading cannons... ', # Use eventlet’s abstraction of a collection of tasks: a GreenPile pile = eventlet.GreenPile(pool) # Spawn a coroutine in our pile for each host for hostname in hostnames: pile.spawn(_setup_a_cannon, hostname) # Iterating the pile causes eventlet to do the work responses = list(pile) return responses
  • 16. Micro  Army:  Cannons  are  GO!   Time  to  blast  some  poor  web  server  (that  you  own)   def fire_cannon(cannon_host, target): ssh_conn = ssh_connect(cannon_host) # 200 simultaneous connections requesting data for 10 seconds remote_command = 'siege -c200 -t10s %s' % (target) # Siege writes stats to stderr response = exec_command(ssh_conn, remote_command, return_stderr=True) return response
  • 17. Micro  Army:  Fire  Cannons!   Same  strategy  as  before,  with  a  GreenPile   def slam_host(cannon_hosts, target): # Familiar pattern pile = eventlet.GreenPile(pool) for hostname in cannon_hosts: pile.spawn(fire_cannon, hostname, target) responses = list(pile) # Parse output from each host for CSV generation report = parse_responses(responses) return report
  • 18. Micro  Army:  Finishing  up.   Just  the  facts,  micro.   Num_Trans,Elapsed,Tran_Rate   3679,                      9.54,              385.64   3635,                      9.48,              383.29   3535,                      9.33,              378.89  
  • 19. Micro  Army:  Recap   • LAUNCH  some  number  of  EC2  micros     • INSTALL  siege,  etc  on  instances     • SLAM  web  host  from  micros  in  parallel     • AGGREGATE  the  results  in  a  CSV    
  • 20. Hopefully  you  learned  how  to…   •  deploy  instances  on  EC2  with  Python   •  execute  a  script  on  many  boxes  in  parallel   •  use  SSH  from  Python   –  You  should  sEll  checkout  Fabric  (fabfile.org)   •  use  the  excellent  module,  Eventlet:   – Free  nonblocking  I/O   – Simple,  but  efficient  concurrency   – Read  the  webpage,  it  actually  gets  beAer   •  Green  threads!    
  • 21. Try  it!   h?ps://github.com/j2labs/microarmy   h?ps://console.aws.amazon.com/ec2/home   Read  more!   h?p://eventlet.net   h?p://www.lag.net/paramiko/   h?p://boto.cloudhackers.com/  
  • 22. Ques1ons   ?   James  Dennis  (@j2labs)   jdennis@gmail.com