Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Keep HTTP connection and cache some responses #55

Conversation

StefanScherer
Copy link
Contributor

I have traced what's going on while a vagrant status call with a vApp containing four VMs.
Both in Vagrant 1.5.x and Vagrant 1.6.2 have been tested.

I wondered why the code loses the env with the 'persisted' vCloud connection in the env hash. Digging down into other plugins and the vagrant code looking at the BatchAction (with and without parallel mode) I come to the point that this seems the way vagrant works these days.
Each action is for a single machine and therefore we 'loose' the connection object.
In parallel mode only each action is called in another thread, but also has to connect to the server (seems that azure and aws plugins are doing this, haven't tested).

So I come up to this approach. After the first connect, we store the connection object in another global variable that lives longer than the env hashes per action.
I have removed the DisconnectVCloud calls, I don't think we need this, only at exit of the vagrant call.
As we don't can use the parallel mode as it is given, I don't think there is a threading problem with this global variable.

Back to my observations:

A vagrant status with four VMs causes the following requests:

"SEND POST https://roecloud001/api/sessions"
"SEND GET https://roecloud001/api/vApp/vapp-d23b1a76-8c76-4287-a0da-22c4e719b931"
"SEND GET https://roecloud001/api/vApp/vapp-d23b1a76-8c76-4287-a0da-22c4e719b931"
"SEND POST https://roecloud001/api/sessions"
"SEND GET https://roecloud001/api/vApp/vapp-d23b1a76-8c76-4287-a0da-22c4e719b931"
"SEND POST https://roecloud001/api/sessions"
"SEND GET https://roecloud001/api/vApp/vapp-d23b1a76-8c76-4287-a0da-22c4e719b931"
"SEND POST https://roecloud001/api/sessions"
"SEND GET https://roecloud001/api/vApp/vapp-d23b1a76-8c76-4287-a0da-22c4e719b931"

With my VPN connection this takes about 14 seconds to retrieve the status of the four boxes - quite long (some latencies per request sum up).

Each POST is a login, each GET retrieves the whole vApp information, so we have all informations for all VMs after the first GET request.
All other requests just respond the same as we do not modify anything in the meantime.

So I gave the send_request another flag cacheable where the most of the GET request will be cached until another method than GET will be used or a task is scheduled and we do a task status GET. All cached data will be thrown away if that happens. This should work quite well, I will test this with further situations.

After the two changes (keep connection + cache responses) the vagrant status of the same vApp looks like this:

"SEND POST https://roecloud001/api/sessions"
"SEND GET https://roecloud001/api/vApp/vapp-fdd5c7eb-9432-4c64-9b37-3e4603981d84"

And only takes about 4 seconds via my VPN. I will try in intranet today, that should be quite faster then. And then the status is fast regardless the number of VMs created in the vApp.

* upstream/develop:
  also show vapp to vm rules
  fix cygdrive path for rsync
  cache return value of get_vapp_edge_public_ip
  added optional vapp_prefix to name the vapp
  removed set_edge_gateway_rules, no longer needed
  add_edge_gateway_rules for DNAT rule per port
  removed edge_gateway_rules code from power_on
  better variable names
  show also HTTP method in debug log
  also check used ports in edge gateway
  removed duplication function poweron_vm
  corrected integer type in Set
  removed get_vapp_port_forwarding_external_ports
  fixed duplicate port forwarding
  retrieve vapp_edge_public_ip after power_on
  Introducing Fix for Issue frapposelli#33 - Changed action_start, action_boot and action_up order of operations.
  always call InventoryCheck in action_up
* upstream/develop: (32 commits)
  Fixes frapposelli#54 - Added vShield Edge Gateway name
  Fixes frapposelli#54 - Added vagrant vcloud --redeploy-edge-gw
  Fixes frapposelli#45 - vCloud Auth token issue
  Fixes frapposelli#53 - Restructure vagrant vcloud-status to vagrant vcloud <namespace>
  Fixes frapposelli#52 - Missed autoload
  Fixes frapposelli#52 - Block Ability to ssh into halted/suspended VMs
  Fixes frapposelli#47 - Shell provisioner error
  Finally fixed API Version checker to work as expected
  version bump.
  Keep waiting on task if it is in 'queued' or 'preRunning' status
  Update README.md
  Version bump
  Modularized the destroy part to fix issue frapposelli#43 - Split poweroff.rb into poweroff_vapp.rb and poweroff_vm.rb. - Split destroy.rb into destroy_vapp.rb and destroy_vm.rb. - Added is_last_vm.rb to check if vApp has a single VM remaining.
  also show vapp to vm rules
  fix cygdrive path for rsync
  cache return value of get_vapp_edge_public_ip
  added optional vapp_prefix to name the vapp
  removed set_edge_gateway_rules, no longer needed
  add_edge_gateway_rules for DNAT rule per port
  removed edge_gateway_rules code from power_on
  ...
@tsugliani tsugliani added this to the v.Next milestone May 13, 2014
@tsugliani tsugliani self-assigned this May 13, 2014
@tsugliani
Copy link
Collaborator

Hi @StefanScherer,

Thanks for the PR !

I need to look into that, any performance improvement is good, but I must do quite some testing to be sure this is harmless, especially with a REST API where objects can change during 2 calls, (Edge Gateway for example, if you have concurrent vagrant deployments) for non common/shared objects, that might be a good performance improvement !

Flagged it as enhancement, but probably will not make it for 0.3.2

@StefanScherer
Copy link
Contributor Author

You're right. With this change there is a problem uploading VM's

b:\GitHub\plossys\qs\100g [less_verbose*]>grep SEND 02-vagrant-up-provider-vcl
oud.log
 INFO driver_5_1: SEND POST https://roecloud001/api/sessions
"SEND POST https://roecloud001/api/sessions"
 INFO driver_5_1: SEND GET https://roecloud001/api/org
"SEND GET https://roecloud001/api/org"
 INFO driver_5_1: SEND GET https://roecloud001/api/org/14f84887-ef1c-4009-a333-0904bdcaf49e
"SEND GET https://roecloud001/api/org/14f84887-ef1c-4009-a333-0904bdcaf49e"
 INFO driver_5_1: SEND GET https://roecloud001/api/vdc/ea5a7837-1f8f-4e5b-8b75-511a7869995f
"SEND GET https://roecloud001/api/vdc/ea5a7837-1f8f-4e5b-8b75-511a7869995f"
 INFO driver_5_1: SEND GET https://roecloud001/api/catalog/7fe962d6-51ff-438b-9e72-eb066e999dd4
"SEND GET https://roecloud001/api/catalog/7fe962d6-51ff-438b-9e72-eb066e999dd4"
 INFO driver_5_1: SEND GET https://roecloud001/api/catalogItem/096145ab-c7ab-437e-843b-f01c21560ba6
"SEND GET https://roecloud001/api/catalogItem/096145ab-c7ab-437e-843b-f01c21560ba6"
 INFO driver_5_1: SEND GET https://roecloud001/api/catalogItem/3b29616a-237a-4774-9a71-4efc92eba3b2
"SEND GET https://roecloud001/api/catalogItem/3b29616a-237a-4774-9a71-4efc92eba3b2"
 INFO driver_5_1: SEND GET https://roecloud001/api/catalogItem/505d8907-67da-45c1-89a2-c9894084cea9
"SEND GET https://roecloud001/api/catalogItem/505d8907-67da-45c1-89a2-c9894084cea9"
 INFO driver_5_1: SEND POST https://roecloud001/api/vdc/ea5a7837-1f8f-4e5b-8b75-511a7869995f/action/uploadVAppTemplate
"SEND POST https://roecloud001/api/vdc/ea5a7837-1f8f-4e5b-8b75-511a7869995f/action/uploadVAppTemplate"
 INFO driver_5_1: SEND GET https://roecloud001/api/vAppTemplate/vappTemplate-ffc2f6b4-47e8-4c47-b265-593a83693a3f
"SEND GET https://roecloud001/api/vAppTemplate/vappTemplate-ffc2f6b4-47e8-4c47-b265-593a83693a3f"

The last GET then will be cached but the debug log shows what will go wrong:

 INFO driver_5_1: put response in cached_response_headers and bodies
DEBUG driver_5_1: Waiting for the upload links to show up in the vAppTemplate we just created.
 INFO driver_5_1: reusing cached_response_headers and bodies
DEBUG driver_5_1: Request...
 INFO driver_5_1: reusing cached_response_headers and bodies
DEBUG driver_5_1: Request...

So I have to remove some of the flags in function that always need up-to-date responses.

@frapposelli frapposelli modified the milestones: v0.4.0, v.Next May 20, 2014
@frapposelli frapposelli modified the milestones: v1.0.0, v0.4.0 May 29, 2014
@StefanScherer StefanScherer deleted the keep_connection_and_cache branch March 16, 2015 06:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants