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=1.0 required=3.0 tests=AWL,HK_RANDOM_FROM, MSGID_FROM_MTA_HEADER,TVD_RCVD_IP shortcircuit=no autolearn=no version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.rainbows.general Subject: Re: background threads Date: Mon, 18 Jun 2012 22:21:05 +0000 Message-ID: <20120618222105.GA460@dcvr.yhbt.net> References: <4FDF7420.7030300@objectdata.com.br> <20120618215550.GA31162@dcvr.yhbt.net> <4FDF7CA0.6030103@objectdata.com.br> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1340058094 8884 80.91.229.3 (18 Jun 2012 22:21:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 18 Jun 2012 22:21:34 +0000 (UTC) To: Rainbows! list Original-X-From: rainbows-talk-bounces-GrnCvJ7WPxnNLxjTenLetw@public.gmane.org Tue Jun 19 00:21:33 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 Content-Disposition: inline In-Reply-To: <4FDF7CA0.6030103-VwDbj2YsoUp0ZRtCdD4y8VAUjnlXr6A1@public.gmane.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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:362 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 1SgkKA-0008JL-NS for gclrrg-rainbows-talk@m.gmane.org; Tue, 19 Jun 2012 00:21:30 +0200 Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id BA9832E06E; Mon, 18 Jun 2012 22:21:30 +0000 (UTC) Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 104422E06B for ; Mon, 18 Jun 2012 22:21:05 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 570551F42D; Mon, 18 Jun 2012 22:21:05 +0000 (UTC) Alexandre Riveira wrote: > Em 18-06-2012 21:55, Eric Wong escreveu: > > What kind of problems? > > The application consumes 100% cpu after reload > > > Is preload_app true or false? (default is false) > preload_app is true With preload_app true, the application worker won't be able to communicate with the background thread after reload. I'm not sure if your setup relies on threads communicating directly with the application. > I changed my code as below and got a result in small servers > Thread.new(log) do |rotina_log| > loop do > log.info("rotina automatica") {"waiting process before end"} > sleep(5) > break unless File.exists? Dir.pwd + '/tmp/pids/rainbows.pid.oldbin' > end > > loop do > #rotina_log.info("rotina automatica") { "waiting 60 secs #{Process.pid}" } > sleep(60) > if $0.include? "old" > rotina_log.info("rotina automatica") { "exit..... #{Process.pid}" } > Thread.exit > end > begin > #rotina_log.info("rotina automatica") { "exec #{Process.pid}" } > empresas = Empresa::Base.find_all_by_cancelado(false) > #sleep(180) > empresas.invoke(:rotinas_automaticas, :usuario_id => Auth::Configuracao.instance.usuario_sistema_id) > #rotina_log.info("rotina automatica") { "exec ok #{Process.pid}" } > rescue Exception => e > rotina_log.fatal("rotina automatica") { e.to_s + e.backtrace.inspect } > end > end > end Reading the code above (but not knowing your original code), I'm not seeing any communcation between the threads. It could probably be done better as a standalone daemon or even a cronjob. There's more setup overhead, sure, but it should also be easier to debug/troubleshoot. _______________________________________________ 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