eventmachine

How to log with Ruby and eventmachine?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 09:47:26
问题 I'm writing an application using Ruby and the Eventmachine library. I really like the idea of non blocking I/O and event driven systems, the problem I'm running into is logging. I'm using Ruby's standard logger library. Its not that logging takes forever but it seems like something that shouldn't block and it does. Is there a library out there somewhere that extends Ruby's standard logger implementation to be non-blocking or should I just call EM::defer for my logging calls? Is there a way I

Which version of eventmachine is able to work in windows?

我怕爱的太早我们不能终老 提交于 2019-12-22 11:29:09
问题 I'm having issues with using eventmachine 0.12.10 in my windows machine. Now my question is, currently, which version of eventmachine is able to work? 回答1: I have Windows 7 ruby 1.9.2p180 (2011-02-18) [i386-mingw32] eventmachine (1.0.0.beta.4.1 x86-mingw32) 来源: https://stackoverflow.com/questions/7659821/which-version-of-eventmachine-is-able-to-work-in-windows

How to write (large) files with Ruby Eventmachine

試著忘記壹切 提交于 2019-12-21 04:50:53
问题 I've spent several days now finding some non-echo-server examples for eventmachine, but there just don't seem to be any. Let's say i want to write a server that accepts a file and writes it to a Tempfile: require 'rubygems' require 'tempfile' require 'eventmachine' module ExampleServer def receive_data(data) f = Tempfile.new('random') f.write(data) ensure f.close end end EventMachine::run { EventMachine::start_server "127.0.0.1", 8081, ExampleServer puts 'running example server on 8081' }

Ruby IMAP IDLE concurrency - how to tackle?

蹲街弑〆低调 提交于 2019-12-20 17:34:09
问题 I'm trying to build a (private, for now) web application that will utilize IMAP IDLE connections to show peoples emails as they arrive. I'm having a hard time figuring out how to hack this together - and how it would fit together with my Heroku RoR server. I've written a basic script for connecting to an IMAP server and idling, looks something like this (simplified): imap = Net::IMAP.new server, port, usessl imap.login username, password imap.select "INBOX" imap.add_response_handler do

How IMAP idle works?

不打扰是莪最后的温柔 提交于 2019-12-18 12:41:05
问题 Can someone explain to me how IMAP IDLE works? Does it fork a new process for each connection that it opens? Can I somehow use eventmachine with it? I am trying to implement it in ruby on heroku with background workers. Any thoughts? 回答1: In Ruby 2.0 and up, there's an idle method that accepts a code block that will be called every time you get an untagged response. Once you got this response, you need to break out and pull the emails that came in. The idle call is also blocking, so you need

What is the best way to read files in an EventMachine-based app?

柔情痞子 提交于 2019-12-18 04:02:33
问题 In order not to block the reactor I would like to read files asynchronously, but I've found no obvious way of doing it using EventMachine. I've tried a few different approaches, but none of them feels right: Just read the file, it'll block the reactor, but what the hell, it's not that slow (unless it's a big file, and then it definitely is). Open the file for reading and read a chunk on each tick (but how much to read? too much and it'll block the reactor, too little and reading will get

Detect if application was started as HTTP server or not (rake task, rconsole etc)

跟風遠走 提交于 2019-12-17 18:55:10
问题 I'm using EventMachine and Monetarily to start e TCP server along with my rails application. This is started from config/initializers/momentarily.rb . My problem is that it starts also when I run rake tasks, like db:migrate . I only want it to start when when I start the HTTP server. Environments won't help, since both the server start and rake tasks are under Development environment. Is there a way of knowing that the application is running the HTTP server as opposed to anything else? Note

Large number of threads under unicorn

前提是你 提交于 2019-12-13 01:01:01
问题 I am in the process of debugging some Posgtres connection leaks in our application. Few days back we suddenly crossed 100 connections when we should not be - coz we just have 8 unicorn workers and a sidekiq process (25 threads). I was looking at htop today and saw that a ton of threads were being spawned from my unicorn workers. Eg: Am I reading this correctly? This should not be happening right? If these are threads being spawned, any idea how to debug this? Thanks! Btw, my other problem -

How to avoid the source being overwritten when compiling a Gem?

扶醉桌前 提交于 2019-12-12 04:58:23
问题 I am trying to install eventmachine Gem, however a line needs to be commented out in the source for this to work on Ruby 2.0 on Windows x64. I have tried modifying the Gem source in the Ruby build folder but each time I run gem install eventmachine it overwrites my changes. From the command line help there does not appear to be a way to rebuild the gem without unpacking fresh source, however there may be a workaround. Is there a way to build my slightly tweaked source for this Gem? 回答1: Don't

Asynchronous HTTP requests with ruby

徘徊边缘 提交于 2019-12-11 11:29:13
问题 I have a rabbitmq queue full of requests and I want to send the requests as an HTTP GET asynchronously, without the need to wait for each request response. now I'm confused of what is better to use, threads or just EM ? The way i'm using it at the moment is something like the following , but it would be great to know if there is any better implementation with better performance here since it is a very crucial part of the program : AMQP.start(:host => "localhost") do |connection| queue = MQ