eventmachine

Is it possible to initiate multiple parallel http requests using EventMachine with Ruby 1.8

喜你入骨 提交于 2020-01-01 16:53:27
问题 em-synchrony.rb implements this feature with Fibers but I would go for a non-Fibre version with 1.8 MRI. EM.run do http = EM::Protocols::HttpClient2.connect("www.google.com", 80) request = http.get("/") request.callback do puts request.status EM.stop end end 回答1: Have a look at em-http-request: EM.run do http1 = EventMachine::HttpRequest.new('http://example.com/1').get http1.callback do p http1.response end http2 = EventMachine::HttpRequest.new('http://example.com/2').get http2.callback do p

Http streaming with thin & eventmachine

我只是一个虾纸丫 提交于 2020-01-01 05:48:27
问题 I'm playing with EM to achieve streaming and concurrency. I had a problem with streaming... I run the following rack app https://gist.github.com/1394840 using $ rackup -s thin -p 3000 async_app.ru While testing with $ ab -c 10 -n 20 http://localhost:3000/ , the app seemed accepting parellel requests. Great! I expect it to achieve streaming meanwhile. When I test it in Firefox8, it works so well. And using $ curl -i http://localhost:3000/ , the result is streamed just as expected too! But

Rails/Ruby Error When Creating Database: Unable to load the EventMachine C extension

為{幸葍}努か 提交于 2019-12-29 06:59:09
问题 Update: the eventmachine gem is installed and in my gemfile: eventmachine (1.0.0, 0.12.10) Please help! Trying to create a database with the following: Fitzs-MacBook-Pro:twilio_insanity Fitz$ rake db:create' Returns the following error: Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' rake aborted! cannot load such file -- rubyeventmachine /Users/Fitz/.rvm/gems/ruby-1.9.3-p327@rails3tutorial2ndEd/gems/eventmachine-1.0.0/lib/eventmachine.rb:8:in

Thin + EventMachine fails to start

谁说我不能喝 提交于 2019-12-25 05:23:09
问题 While loading a Thin webserver for a sinatra app I keep getting Unable to load the EventMachine C extension; To use the pure-ruby reactor, require em/pure_ruby'<path>/vendor/bundle/ruby/1.9.1/gems/eventmachine-1.0.0.rc.4/lib/eventmachine.rb:8:in `require': cannot load such file -- rubyeventmachine (LoadError) from <path>/vendor/bundle/ruby/1.9.1/gems/eventmachine-1.0.0.rc.4/lib/eventmachine.rb:8:in `<top (required)>' from <path>/vendor/bundle/ruby/1.9.1/gems/thin-1.5.0/lib/thin.rb:7:in

I Can't install EventMachine in Windows

瘦欲@ 提交于 2019-12-24 18:43:55
问题 I just try to install EventMachine with RubyGems : (gem install eventmachine). I use Windows 7 x64. I get this error : C:/Ruby/193/bin/ruby.exe extconf.rb checking for rb_trap_immediate in ruby.h,rubysig.h... no checking for rb_thread_blocking_region()... yes checking for inotify_init() in sys/inotify.h... no checking for __NR_inotify_init in sys/syscall.h... no checking for writev() in sys/uio.h... no checking for rb_thread_check_ints()... yes checking for rb_time_new()... yes checking for

Running a modular Sinatra app with Thin and EventMachine. It starts twice?

蹲街弑〆低调 提交于 2019-12-24 14:26:48
问题 I have a modular Sinatra web app running using Thin, with EventMachine running additional tasks. It works, but there's something a bit odd about the webserver: Any requests, whether successful or 404s, don't appear in the log output from Thin/Sinatra. And when I cancel the process, the server ends twice. Here's the rough, basic structure of the app: Procfile: web: ruby app.rb app.rb: require 'thin' require 'eventmachine' require 'app/frontend' EM.run do # Start some background tasks here...

Ruby failing to override send method

白昼怎懂夜的黑 提交于 2019-12-24 13:34:08
问题 This is a bit hard to explain, but I seem to be occasionally unable to override the 'send' method in my application. I'm creating a fairly large application based on EventMachine and sometimes, deep in the bowels of my code, I decide to define a 'send' method in one of my classes. When I later attempt to use this method, I normally get an exception that looks something like TypeError: <parameter> is not a symbol , such as the following (happens to be caused by the required AMQP gem (not mine)

Any ideas how to create parameterised streaming api?

坚强是说给别人听的谎言 提交于 2019-12-24 12:15:45
问题 I want to create parameterised streaming api like http://dev.twitter.com/pages/streaming_api_methods#statuses-filter The straightforward way I see is following: Create redis channel for messages (like twitter statuses). Each connected socket subscribes on this channel. Inside redis callback each sockets check if current message fits supplied parameters (parameters could be set as separate socket message) What you think guys? 回答1: You might want to look at nats 来源: https://stackoverflow.com

what is the advantage of EventMachine

感情迁移 提交于 2019-12-24 02:35:23
问题 This is my test case, I found that the EM is not faster than the general TCP server the EM server: require 'rubygems' require 'benchmark' require 'eventmachine' class Handler < EventMachine::Connection def receive_data(data) operation = proc do # simulate a long running request a = [] n = 5000 for i in 1..n a << rand(n) a.sort! end end # Callback block to execute once the request is fulfilled callback = proc do |res| send_data "send_response\n" end puts data EM.defer(operation, callback) end

Ruby on Rails: “cannot load such file” eventmachine

倾然丶 夕夏残阳落幕 提交于 2019-12-23 17:45:07
问题 I'm in the middle of trying to run an RoR app on my Windows machine. I've made a lot of progress with getting everything configured, but I'm stuck here. When I try to run rake, I get the following error: C:\inetpub\wwwroot\voterApp>rails server C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- eventmachine (LoadError) from C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.0/lib/active_support/dependencies.rb:251