Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Implementações paralelas

1,284 views

Published on

Palestra sobre implementações paralelas feita na Locaweb e no GuruSP.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Implementações paralelas

  1. 1. Implementações paralelas Willian Molinari a.k.a PotHix
  2. 2. WTF
  3. 3. 1996!!John Carmack
  4. 4. https://github.com/id-Software
  5. 5. #AltDevBlogADay
  6. 6. Várias formas deimplementações paralelas
  7. 7. 1. Substitution
  8. 8. Master
  9. 9. Código no branch principalclass VirtualMachine def name hypervisor_session.VM.get_name(uuid) end . . .end
  10. 10. Código código no branch novoclass VirtualMachine def name on_hypervisor.VM.get_name(uuid) end . . .end
  11. 11. Master NewFeatureFeature
  12. 12. "Virar a chave"
  13. 13. Dá para evitar?
  14. 14. 2. Feature Toggle
  15. 15. 2. Feature TogglePara adição de funcionalidade
  16. 16. Martin Fowler http://martinfowler.com/bliki/FeatureToggle.html
  17. 17. MasterFeature1 Merge ReleaseFeature2Feature3
  18. 18. Martin Fowler http://martinfowler.com/bliki/FeatureToggle.html
  19. 19. Nando Vieira http://simplesideias.com.br/usando-presenters-no-rails/
  20. 20. 2. Feature TogglePara várias implementações
  21. 21. Fabio Kung http://fabiokung.com/2010/10/16/dsls-one-interface-multiple-implementations/
  22. 22. Qual a idéia?
  23. 23. module Resque class Consumer class << self def queue(name) @queue = name end def timeout(seconds=nil) @lock_timeout = seconds unless seconds @lock_timeout || 1.hour end def exclusive(param) @exclusive = param self.extend(Resque::Plugins::LockTimeout) if exclusive? @lock_timeout ||= 1.hour end def publish(message={}) Resque.enqueue(self, message) end ... end endend
  24. 24. module ActiveMQ class Consumer class << self attr_reader :queue_name, :queued_process, :headers, :timeout_value def queue(name) @queue_name = "/queue/#{name}" end def timeout(seconds) @timeout_value = seconds end def exclusive(param) @exclusive = param end def publish(message = {}) client = Stomp::Client.new(NephelaeConfig[:broker].merge(:max_reconnect_attempts => 1)) client.publish(queue_name, message.to_yaml, { :persistent => true, :suppress_content_length => true }) end ... end endend
  25. 25. require xmpp4rmodule XMPP class Consumer class << self attr_reader :queue_name, :queued_process, :timeout_value def queue(name) @queue_name = "#{name}@localhost" end def timeout(seconds) @timeout_value = seconds end def exclusive(param) @exclusive = param end def publish(message={}) publisher_client.send(Jabber::Message.new(queue_name, message.to_yaml)) end ... end endend
  26. 26. app/consumers/consumer.rb Consumer = ActiveMQ::Consumer
  27. 27. app/consumers/consumer.rb Consumer = XMPP::Consumer
  28. 28. app/consumers/consumer.rb Consumer = Resque::Consumer
  29. 29. Injeção de dependenciaMyQueue.new(Resque::Consumer)
  30. 30. Por configuração
  31. 31. 3. Feature versioning
  32. 32. ManagerVer1 Ver2
  33. 33. module Network class Ver1 def insert_filter_rule(filter_rule) filter_rule.firewalls.in_parallel do |firewall| ssh_executor = SSHExecutor.new(firewall.ip_address, sservice) result = ssh_executor.exec( :insert_filter_firewall_rules, :rule => filter_rule, :internal_address => filter_rule.ip_pair.private_ip, :firewall => firewall ) raise "Insertion failed: #{result[:out]}" if result[:status] != 0 end filter_rule.update_attribute(:status, :done) end def insert_dhcp_entry(vm) vm.zone.dhcps.in_parallel do |dhcp_server| result = dhcp_server.synchronize raise "DHCP failed: #{result[:out]}" if result[:status] != 0 end end endend
  34. 34. ManagerVer1 Ver2
  35. 35. module Network class Ver2 def insert_filter_rule(filter_rule) quantum = Openstack::QuantumClient::L2l3.new(NephelaeConfig[:quantum]) quantum_response = quantum.filter_rule.create( filter_rule.filter_address, filter_rule.ip_pair.public_ip.to_s, filter_rule.filter_port, filter_rule.filter_protocol ) filter_rule.update_attribute(:quantum_uuid, quantum_response["filter_rule"]["id"]) end def insert_dhcp_entry(vm) quantum = Openstack::QuantumClient::L2l3.new(NephelaeConfig[:quantum]) quantum_response = quantum.dhcp_entry.create(vm.public_ip.to_s, vm.mac, vm.name) endend
  36. 36. Manager"1.0" "2.0"Ver1 Ver2
  37. 37. module Network module Manager extend self def for(versioning_object) versioning_object.version == "2.0" ? Network::Ver2.new : Network::Ver1.new end endend
  38. 38. module Network module Manager extend self def for(versioning_object) versioning_object.version.constantize.new end endendNetwork::Manager.for(pool).insert_filter_rule(virtual_machine)
  39. 39. Várias formas de atacar o problema r bu llet os ilveN Resumindo Su bene fício an ec Cu sto X es sida de
  40. 40. Perguntas?

×