eventmachine

Ctrl+C not killing Sinatra + EM::WebSocket servers

纵然是瞬间 提交于 2019-12-11 11:16:35
问题 I'm building a Ruby app that runs both an EM::WebSocket server as well as a Sinatra server. Individually, I believe both of these are equipped to handle a SIGINT. However, when running both in the same app, the app continues when I press Ctrl+C. My assumption is that one of them is capturing the SIGINT, preventing the other from capturing it as well. I'm not sure how to go about fixing it, though. Here's the code in a nutshell: require 'thin' require 'sinatra/base' require 'em-websocket'

No perfomance gains from using em-http-request

被刻印的时光 ゝ 提交于 2019-12-11 09:32:27
问题 I'm trying to understand how to use various non-blocking IO libraries in Ruby and made a simple app for testing using Sinatra, # proxy.rb require 'bundler/setup' require 'sinatra/base' require 'sinatra/synchrony' require 'faraday' class ProxyApp < Sinatra::Base register Sinatra::Synchrony get "/proxy" do conn = Faraday.new("http://mirror.yandex.ru") do |faraday| faraday.use Faraday::Adapter::EMSynchrony end conn.get "/ubuntu-releases/precise/ubuntu-12.04.1-alternate-i386.iso" "Hello, world"

Ruby Eventmachine & HTTP requests via proxy

送分小仙女□ 提交于 2019-12-11 07:15:58
问题 I'm coding on a high scalable web harvester running on top of Eventmachine. All works fine and fast. Recently I'm trying to fire the requests through a bunch of proxies which also works fine, e.g.: EventMachine.run do connect_opts = { :proxy => { :host => '11.12.13.14', :port => 3128 } } request_opts = { :proxy => { :authorization => ['jdoe', 'mysecretpass'] } } req = EventMachine::HttpRequest.new('http://www.example.com/', connect_opts).get request_opts req.callback { } end I'm iterating

Why are there so many “TIME_WAIT” connectings when using EventMachine?

梦想的初衷 提交于 2019-12-11 04:33:32
问题 When I run my test code for EventMachine, I found there are too many " TIME_WAIT " connections. Is it a problem? run netstat -anp | grep 8080 tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 13012/ruby tcp 0 0 127.0.0.1:38701 127.0.0.1:8080 TIME_WAIT - tcp 0 0 127.0.0.1:38706 127.0.0.1:8080 TIME_WAIT - tcp 0 0 127.0.0.1:38709 127.0.0.1:8080 TIME_WAIT - tcp 0 0 127.0.0.1:38708 127.0.0.1:8080 TIME_WAIT - tcp 0 0 127.0.0.1:38699 127.0.0.1:8080 TIME_WAIT - tcp 0 0 127.0.0.1:38700 127.0.0.1:8080 TIME_WAIT -

Testing EventMachine with cucumber

家住魔仙堡 提交于 2019-12-10 18:17:27
问题 I'm trying to write a cucumber feature and rspec tests for my application for accessing the twitter streaming api with twitter-stream. I've got the following code: Then /^I should see the latest (\d+) tweets from my timeline$/ do |num| timeline = Starling::Timeline::Mine.new(@store) EventMachine::run { tweets = timeline.latest timeline.stop } tweets.length.should == num.to_i end the code for the method is: def latest token = @token.get_token @stream = Twitter::JSONStream.connect(options)

Thin/eventmachine non-root installation problem

杀马特。学长 韩版系。学妹 提交于 2019-12-10 12:24:21
问题 Trying to run ruby on rails framework under nginx+thin, currently working under WEBrick. I don't have root access, cause it is hosted at web hosting service. Till this moment all problems with gems solved w/o root access. thin requires eventmachine, so: $ gem install eventmachine Building native extensions. This could take a while... ERROR: Error installing eventmachine: ERROR: Failed to build gem native extension. /usr/local/bin/ruby18 extconf.rb checking for rb_trap_immediate in ruby.h

Eventmachine gem permission denied

空扰寡人 提交于 2019-12-10 12:15:05
问题 I'm trying to run $gem install eventmachine -v '0.12.10' because when running $bundle install within my rails app, when it gets to eventmachine I get this error: Installing eventmachine (0.12.10) Errno::EACCES: Permission denied - /Users/pippinlee/.rvm/gems/ruby-1.9.3-p194/gems/eventmachine-0.12.10/.gitignore An error occured while installing eventmachine (0.12.10), and Bundler cannot continue. Make sure that `gem install eventmachine -v '0.12.10'` succeeds before bundling. I have tried

EventMachine : How to build a chat system with Rails application

谁都会走 提交于 2019-12-10 05:53:17
问题 I am building a chat system using EventMachine and ruby on rails. It's for learning purpose. This is how client is connecting to server. c = TCPSocket.open(ip_address, port) data = {:user_id => 2, :message => 'hello world'} c.send(data) response = c.gets c.close It works. However the problem is that I can't get the list of people who are currently chatting in the room because as I shown above, client is constantly opening and closing the connection. An alternative plan is to run an

Multiple Ruby EventMachines in one process: possible?

冷暖自知 提交于 2019-12-09 18:10:09
问题 I have a situation where I want to run multiple EventMachines in Ruby - does anyone have experience with this? (I may write a test case to do it myself if not. Stay tuned). Let's be clear: I want to instantiate two threads myself, and call EventMachine.run in both threads, so I really have two reactor loops. The reason why is that I'm writing an asynchronous message bus with the AMQP gem, which uses EventMachine. That's fine, but I want to make that a separate, modular component that can be

How to hand-over a TCP listening socket with minimal downtime?

蹲街弑〆低调 提交于 2019-12-09 16:08:17
问题 While this question is tagged EventMachine, generic BSD-socket solutions in any language are much appreciated too. Some background: I have an application listening on a TCP socket. It is started and shut down with a regular System V style init script. My problem is that it needs some time to start up before it is ready to service the TCP socket. It's not too long, perhaps only 5 seconds, but that's 5 seconds too long when a restart needs to be performed during a workday. It's also crucial