From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS33070 50.56.128.0/17 X-Spam-Status: No, score=0.0 required=3.0 tests=AWL,MSGID_FROM_MTA_HEADER, TVD_RCVD_IP shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: "Lin Jen-Shin (godfat)" Newsgroups: gmane.comp.lang.ruby.rainbows.general Subject: Re: negative timeout in Rainbows::Fiber::Base Date: Sun, 26 Aug 2012 08:12:52 +0800 Message-ID: References: <20120825024556.GA25977@dcvr.yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1345940047 22854 80.91.229.3 (26 Aug 2012 00:14:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 26 Aug 2012 00:14:07 +0000 (UTC) To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Original-X-From: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Sun Aug 26 02:14:05 2012 Return-path: Envelope-to: gclrrg-rainbows-talk@m.gmane.org X-Original-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Delivered-To: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=godfat.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=B0Amm9mB6zORFQrivou4kVLzcObBPQxaQ51a70qzb3I=; b=m7MYEuyo0dc9NvciMyJZUK78UxFM8K3BIozKDMaSFo/xuKZR554NqzgxYqu+fZprwE gmU6pMJCVArGfgwY9eKN3KxIz71phptBp8eMY6/rASaB50/oiGgCyb1SP+AbTvdiOjvb PfauzRr3rvN2ARQn6NGYxk/6vFJ8rQCZOWWNI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:x-gm-message-state; bh=B0Amm9mB6zORFQrivou4kVLzcObBPQxaQ51a70qzb3I=; b=jFjbq3FoRd2+MMcG4L283DDdzw1q86Isq9EkwJOxjlXEOTZEuRMyny7A7qAe32CXOm pI6B4yCLutQlfMUfq3FHyXyNYkC72szRaEpbpHZxKo+WYhMKoGehCpSpFvX/FRHw81lh +TXExXYP0wo/vyyIOuLeKA7iwt6CG/0DJs9Wbr1jnJ/T2L+1D5RPG1ytvW8iG8XjopS3 1U/FdMaFEKF+2N9P55qLRZHqZwLHo3DzjoU/jp7+NIZUNiLghpU411b61M0JroPg3Ynv cwJCXdc3j0G5Mk5rWyqtYv0tTysSXY5RB/d3jFYDhwQI4g4/uNFQEK9mWFgk5irWycP4 394Q== In-Reply-To: <20120825024556.GA25977-yBiyF41qdooeIZ0/mPfg9Q@public.gmane.org> X-Gm-Message-State: ALoCoQnM8+QyzjRKpal66Qf99JuLX0dNu8eHl7PA0WeOR+5m3EkDjabfGLZ04Yw8cdyNJ7Qr4PUo X-BeenThere: rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Errors-To: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Xref: news.gmane.org gmane.comp.lang.ruby.rainbows.general:396 Archived-At: Received: from 50-56-192-79.static.cloud-ips.com ([50.56.192.79] helo=rubyforge.org) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T5QUN-00086A-Qa for gclrrg-rainbows-talk@m.gmane.org; Sun, 26 Aug 2012 02:14:04 +0200 Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id B80B32E067; Sun, 26 Aug 2012 00:14:00 +0000 (UTC) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com [209.85.217.178]) by rubyforge.org (Postfix) with ESMTP id 055DA2E061 for ; Sun, 26 Aug 2012 00:13:24 +0000 (UTC) Received: by lbok6 with SMTP id k6so2120704lbo.23 for ; Sat, 25 Aug 2012 17:13:23 -0700 (PDT) Received: by 10.152.125.133 with SMTP id mq5mr9967568lab.12.1345940003034; Sat, 25 Aug 2012 17:13:23 -0700 (PDT) Received: by 10.114.71.44 with HTTP; Sat, 25 Aug 2012 17:12:52 -0700 (PDT) On Sat, Aug 25, 2012 at 10:45 AM, Eric Wong wrote: > The original code looks wrong and confusing :x I guess I know your intension in the new code now :) I can't apply the new patch, so I'll assume the new code is as following: fibs.each { |fib| fib.resume } max_sleep = 1.0 if max max -= Time.now return 0 if max < 0.0 return max_sleep if max > max_sleep max else max_sleep end I once thought that if `max < Time.now`, it should return 0, because apparently we don't want to wait in this case. But I am not sure if passing timeout as 0 would mean to wait forever... thinking that maybe 0.0001 might be better? Not sure if this would be a concern, or 0 means don't wait at all, that would be ideal in this case. > It's been a while since I've looked hard at the Fiber* stuff (not a fan > of it personally). However, I don't think abs() is correct, either. I can smell from the code that those are not well polished, since it seems a lot of things are missing. For example, there is Rainbows::Fiber::IO::Socket, but no TCPSocket. I blindly tried to create a TCPSocket version by creating a new class extended from Kgio::TCPSocket and include Rainbows::Fiber::IO::Methods. Well, I think it works, if using correctly, for example it does not accept domain names as built-in TCPSocket, and not all of the methods are respecting fibers. But I like the idea to patch the socket, that way, we can turn existing library to run under certain network architecture. For instance, this HTTP client accepts passing different socket class: https://github.com/tarcieri/http/blob/master/lib/http/options.rb#L33-37 @default_socket_class = TCPSocket @default_ssl_socket_class = OpenSSL::SSL::SSLSocket class << self attr_accessor :default_socket_class, :default_ssl_socket_class I didn't try if passing Rainbows' fiber sockets would work or not, but I think in theory it should work. I think Tony did this for his: https://github.com/celluloid/celluloid-io Quoted from README: """ Replacement classes: Celluloid::IO includes replacements for the core TCPServer and TCPSocket classes which automatically use an evented mode inside of Celluloid::IO actors. They're named Celluloid::IO::TCPServer and Celluloid::IO::TCPSocket, so they're automatically available inside your class when you include Celluloid::IO. """ Not sure if this is the way to go, but an interesting idea. At least better than implementing every single client in both eventmachine and built-in sockets I guess... So speaking to celluloid-io, there's already Revactor and Coolio support, what about celluloid-io? Last time I tried Coolio, occasionally it would crash with internal assertion failures... I would love to see if there's other alternatives to eventmachine. Also, there is CoolioFiberSpawn, CoolioThreadPool and so on so forth, why not EventMachineFiberSpawn and EventMachineThreadPool? Actually we are running EventMachineFiberSpawn on production at the moment, as shown in: https://github.com/cardinalblue/rest-more/blob/master/example/rainbows.rb#L15-19 class REMFClient < Rainbows::EventMachine::Client def app_call input Fiber.new{ super }.resume end end (well, neverblock works too, but it doesn't seem to be maintained now and I don't understand why it's a gem with a lot of codes but not as simple as above. As this sense, I feel async_sinatra is so wrong, but not sure if I missed something here.) It works great for us at the moment, though I am thinking about switching to threads, too, since it's a lot more flexible than fibers. Sorry that I might be asking too many questions in a single thread. If you're interested in how I am testing them, I put my testing codes at: https://github.com/godfat/ruby-server-exp I am thinking about if I should be giving a talk on rubyconf.tw about ruby application servers, promoting unicorn family. It is one of the reasons to try out all of the options. Thanks for your time :D _______________________________________________ Rainbows! mailing list - rainbows-talk-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org http://rubyforge.org/mailman/listinfo/rainbows-talk Do not quote signatures (like this one) or top post when replying