Algumas considerações sobre criação de aplicações Ruby usando conceitos de concorrência e paralelismo.
Apresentação feita em 08/12/2012 no Rupy Brasil.
do |b| b.report('get normal') do 10.times { Net::HTTP.get_response uri } end end b.report('get maroto') do 10.times.map do Thread.new{ Net::HTTP.get_response uri } end.map(&:join) end Sunday, December 9, 12
Benchmark.bm do |x| x.report "select fuleiro" do 15.times do end end end mysql2 = Mysql2::Client.new host: "localhost", username: "root" Sunday, December 9, 12
Benchmark.bm do |x| x.report "select fuleiro" do 15.times do end end end mysql2 = Mysql2::Client.new host: "localhost", username: "root" mysql2.query "use mysql" Sunday, December 9, 12
Benchmark.bm do |x| x.report "select fuleiro" do 15.times do end end end mysql2 = Mysql2::Client.new host: "localhost", username: "root" mysql2.query "use mysql" mysql2.query sql_fuleiro Sunday, December 9, 12
def pluzz(how_much) @counter = @counter + how_much end end omg = SomatorOMG.new (1..100).map do Thread.new{ } end 100.times { omg.pluzz(1) } Sunday, December 9, 12
def pluzz(how_much) @counter = @counter + how_much end end require 'monitor' include MonitorMixin super # WAT? .. extend(MonitorMixin) Sunday, December 9, 12
def pluzz(how_much) @counter = @counter + how_much end end require 'monitor' include MonitorMixin synchronize do end super # WAT? .. extend(MonitorMixin) Sunday, December 9, 12
EchoServer def post_init puts "-- someone connected to the echo server!" end def receive_data data send_data ">>> you sent: #{data}" end end EventMachine::run { EventMachine::start_server "127.0.0.1", 8081, EchoServer puts 'running echo server on 8081' } Sunday, December 9, 12
EchoServer def post_init puts "-- someone connected to the echo server!" end def receive_data data send_data ">>> you sent: #{data}" end end EventMachine::run { EventMachine::start_server "127.0.0.1", 8081, EchoServer puts 'running echo server on 8081' } Sunday, December 9, 12
Echo < EventMachine::Connection def post_init send_data 'Hello' end def receive_data(data) p data end end EventMachine.run { EventMachine.connect '127.0.0.1', 8081, Echo } Sunday, December 9, 12
Echo < EventMachine::Connection def post_init send_data 'Hello' end def receive_data(data) p data end end EventMachine.run { EventMachine.connect '127.0.0.1', 8081, Echo } Sunday, December 9, 12