Return-Path: X-Original-To: apmail-tomcat-users-archive@www.apache.org Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 20264D88D for ; Sat, 26 Jan 2013 14:07:32 +0000 (UTC) Received: (qmail 25895 invoked by uid 500); 26 Jan 2013 14:07:29 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 25324 invoked by uid 500); 26 Jan 2013 14:07:22 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 25272 invoked by uid 99); 26 Jan 2013 14:07:20 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Jan 2013 14:07:20 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS,UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of Chuck.Caldarale@unisys.com designates 216.82.243.50 as permitted sender) Received: from [216.82.243.50] (HELO mail1.bemta8.messagelabs.com) (216.82.243.50) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Jan 2013 14:07:09 +0000 Received: from [216.82.241.196:17945] by server-14.bemta-8.messagelabs.com id 94/FC-15665-7F2E3015; Sat, 26 Jan 2013 14:06:47 +0000 X-Env-Sender: Chuck.Caldarale@unisys.com X-Msg-Ref: server-4.tower-46.messagelabs.com!1359209205!28771102!14 X-Originating-IP: [192.61.61.104] X-StarScan-Received: X-StarScan-Version: 6.7; banners=-,-,- X-VirusChecked: Checked Received: (qmail 21131 invoked from network); 26 Jan 2013 14:06:47 -0000 Received: from unknown (HELO USEA-NAEDGE1.unisys.com) (192.61.61.104) by server-4.tower-46.messagelabs.com with RC4-SHA encrypted SMTP; 26 Jan 2013 14:06:47 -0000 Received: from usea-nahubcas1.na.uis.unisys.com (129.224.76.114) by USEA-NAEDGE1.unisys.com (192.61.61.104) with Microsoft SMTP Server (TLS) id 8.3.83.0; Sat, 26 Jan 2013 08:06:36 -0600 Received: from USEA-EXCH8.na.uis.unisys.com ([129.224.76.41]) by usea-nahubcas1.na.uis.unisys.com ([129.224.76.114]) with mapi; Sat, 26 Jan 2013 08:06:35 -0600 From: "Caldarale, Charles R" To: Tomcat Users List Date: Sat, 26 Jan 2013 08:06:34 -0600 Subject: RE: [OT] Best way to log requests from a servlet and to a database? Thread-Topic: [OT] Best way to log requests from a servlet and to a database? Thread-Index: Ac37y8qUL1VUhwUJT4iotTe/eP3LmA== Message-ID: <99C8B2929B39C24493377AC7A121E21FC49DCE3FF1@USEA-EXCH8.na.uis.unisys.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org > From: Brian Braun [mailto:brianbraun@gmail.com]=20 > Subject: Re: Best way to log requests from a servlet and to a database? (Marking this off-topic, since it has nothing to do with Tomcat.) > My current method can hold about 3000 threads until memory collapses. I'm > looking to replace this method with something more efficient in terms of > RAM usage. Something like a buffer, where each item needs far less RAM th= an > the kind of threads I'm creating now. Then when it gets full I will use > Amazon's queue as a failover mechanism.Any ideas? :-) Instead of using one additional thread per log entry, use just _one_ additi= onal logging service thread. When each request processing thread has prepa= red the object representing the log entry to be made, that object should be= placed on a synchronized FIFO queue. If the logging service thread is idl= e, the request processing thread should mark the logging service thread as = active and wake it up before unlocking the queue; if the logging service th= read is already active, the request processing thread just unlocks the queu= e after enqueuing its entry. When the logging service thread wakes up, it = must lock the queue, remove _all_ the entries currently on the queue, unloc= k the queue, and send all the removed entries to the database in as few cal= ls as possible. Once that's done, the logging service thread relocks the q= ueue, checks for any new arrivals and repeats as needed. If no new arrival= s, it marks itself as inactive, and goes to sleep on the queue. No polling= required. You can use the standard synchronization methods (wait(), notify(), etc.) f= or all this (safest), or the newer but easier to abuse java.util.concurrent= operations. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MA= TERIAL and is thus for use only by the intended recipient. If you received = this in error, please contact the sender and delete the e-mail and its atta= chments from all computers. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org