eventmachine

Simple use of EM::Synchrony#sync causes 'root fiber' FiberError — my fault?

℡╲_俬逩灬. 提交于 2019-12-09 14:02:13
问题 This program require 'em-synchrony' ## v1.0.0 require 'em-hiredis' ## v0.1.0 module EventMachine module Hiredis class Client def self.connect(host = 'localhost', port = 6379) conn = new(host, port) EM::Synchrony.sync conn.connect conn end alias :old_method_missing :method_missing def method_missing(sym, *args) EM::Synchrony.sync old_method_missing(sym, *args) end end end end EventMachine.synchrony do redis = EM::Hiredis.connect redis.set('foo', 'bar') puts redis.get('foo') EM.stop end dies

cannot start sinatra process - eventmachine “no acceptor”

Deadly 提交于 2019-12-08 19:39:46
问题 I have a Sinatra app that I run as a daemon, using Apache port-forwarding to mediate between port 80 and port 7655. This has been working fine in the past. Today, not so well. I cannot figure out why. Problem: sudo ruby my_process.rb returns: /var/lib/gems/1.9.1/gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError) Tried: updating all system packages, updating all gems. No help (except for the more clear

Reliable timing with EventMachine periodic timers

半世苍凉 提交于 2019-12-08 07:51:29
问题 My objective is to have a system that broadcasts an ad every 10 minutes for 37,500 cities. It takes around 5 minutes do the DB queries, calculations, and AMQP IO for all cities. The code is roughly structured like: EventMachine.add_periodic_timer(10 minutes) do the_task_that_takes_five_minutes end What I'm finding is that even though the timer is set for 10 minute intervals and even though the task takes less than ten minutes the command fires in 15 minute intervals (the time it takes to

EventMachine and looping

空扰寡人 提交于 2019-12-07 06:26:08
问题 Here is my code: EventMachine.run { conn = EM::Protocols::HttpClient2.connect request.host, 80 req = conn.get(request.query) req.callback { |response| p(response.status) p(response.headers) p(response.content) } } The callbacks fire, that is, I get the string outputs of the status, etc. But what I want it to do is fire the callbacks, then repeat. There is more logic I plan to implement, such as tweaking the URL each time, but for now, I just want it to: Retrieve the URL Fire the callbacks

how to solve 'connection is still waiting for a result' error with em_mysql2

别来无恙 提交于 2019-12-07 06:26:03
问题 I'm using activerecord with em_mysql2 under Goliath (eventmachine). The oddest thing is happening with my User model. When I do a POST to /users the first time, it all works just find as expected. When I do a second POST I get an error. Mysql2::Error: This connection is still waiting for a result, try again once you have the result: INSERT INTO `users` (... and so on ...) This doesn't happen for any other of my models or routes. I would assume that if the db connection is in a messed up state

Eventmachine start_tcp_server no acceptor - port is in use or requires root privileges (RuntimeError)

痞子三分冷 提交于 2019-12-07 05:45:10
问题 I haven't been able to run my local server for 3 days now. Restarting my computer doesn't help. A couple of time, after trying repeatedly about 40-50 times, it randomly worked - I can't figure out why. I tried a different port once and that worked, but since then, no port works. Every time I try to run my rails server I get this. /Users/colmtuite/.rvm/gems/ruby-2.2.0/gems/eventmachine-1.0.5/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges)

Error installing gem failed to build gem native extensions — cannot load such file — mkmf

时光怂恿深爱的人放手 提交于 2019-12-07 05:21:13
问题 RoR is nice, but sometimes makes me want to bang my head against the wall (and it's probably my fault anyway). I'm simply trying to install the Thin web-client gem, and when I run sudo gem install thin , I get the following error (it requires the installation of the eventmachine gem first): sudo gem install thin Fetching: eventmachine-1.0.1.gem (100%) Building native extensions. This could take a while... ERROR: Error installing thin: ERROR: Failed to build gem native extension. /usr/bin

How do you catch exceptions in an EventMachine implementation?

余生颓废 提交于 2019-12-07 03:11:39
问题 I have a similar problem to this other post and I've tried the given solutions but to no avail. My project is a Ruby bot that uses the Blather library to connect to a Jabber server. The problem is that when there is a problem with the server and Blather generates an exception the whole program exits and I have no opportunity to catch the exception. Here is some simple code that shows the problem. There is no Jabber server running on localhost so the Blather client throws an exception. I was

Rubyracer (V8 binding for Ruby) performs really slow

折月煮酒 提交于 2019-12-06 13:02:41
So, I have a TCP server in eventmachine and therubyracer is used as a way to pre-pend operations (like filters or extensions) to the server. It all works charming when the server is not receiving a lot of data, but when it's being flooded (it is required sometimes) it becomes really slow. So, I did a small benchmark to see how slower the rubyracer is compared to Ruby, and I was shocked when I saw the results: user system total real V8: 0.060000 0.000000 0.060000 ( 0.059903) Ruby: 0.000000 0.000000 0.000000 ( 0.000524) I don't mind if it's slow, to be honest, but I don't want it to lock up my

Better use EM.next_tick or EM.defer for long running calculation with Eventmachine?

℡╲_俬逩灬. 提交于 2019-12-06 08:46:29
问题 I am trying to figure out how to make use of deferrables when it comes to long running computations that I have to implement on my own. For my example I want to calculate the first 200000 Fibonacci numbers but return only a certain one. My first attempt of a deferrable looked like so: class FibA include EM::Deferrable def calc m, n fibs = [0,1] i = 0 do_work = proc{ puts "Deferred Thread: #{Thread.current}" if i < m fibs.push(fibs[-1] + fibs[-2]) i += 1 EM.next_tick &do_work else self.succeed