Return-Path: Delivered-To: apmail-jakarta-tomcat-user-archive@www.apache.org Received: (qmail 83498 invoked from network); 2 Aug 2004 18:53:54 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 2 Aug 2004 18:53:54 -0000 Received: (qmail 56713 invoked by uid 500); 2 Aug 2004 18:52:34 -0000 Delivered-To: apmail-jakarta-tomcat-user-archive@jakarta.apache.org Received: (qmail 56605 invoked by uid 500); 2 Aug 2004 18:52:33 -0000 Mailing-List: contact tomcat-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Users List" Reply-To: "Tomcat Users List" Delivered-To: mailing list tomcat-user@jakarta.apache.org Received: (qmail 56544 invoked by uid 99); 2 Aug 2004 18:52:33 -0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received: from [65.206.241.134] (HELO lithium.nextengine.com) (65.206.241.134) by apache.org (qpsmtpd/0.27.1) with ESMTP; Mon, 02 Aug 2004 11:52:29 -0700 Received: from justinr2-2000.nextengine.com ([65.206.241.133]) by lithium.nextengine.com (8.11.6/8.11.6) with ESMTP id i72IqL910345 for ; Mon, 2 Aug 2004 11:52:21 -0700 Message-Id: <6.0.0.22.2.20040802112739.032c3860@pop.synerdyne.com> X-Sender: justinr@pop.synerdyne.com X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Mon, 02 Aug 2004 11:52:20 -0700 To: "Tomcat Users List" From: Justin Ruthenbeck Subject: Re: How can I display number of requests over the past n seconds? In-Reply-To: <20040729141054.43040.qmail@web53203.mail.yahoo.com> References: <20040729141054.43040.qmail@web53203.mail.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N More academic exercise than recommendation, but... Write your own implementation of a Map/HashMap specific to java.util.Date objects. Identify your smallest time increment (5 seconds in your email). Identify largest time increment (60 seconds) Create (60/5)+1 buckets for your hash function Write your hash function such that each date object -- representing one request each -- gets placed in the right bucket. If the bucket contains "aged" dates, which you should know by simple counting (not comparison), empty it before placing a new one in. To display results, simply add up the content size of the appropriate buckets and return. This implementation is more lightweight than others suggested because the process of pruning is built into your implementation (instead of using external threads or comparisons each time you insert)... you're trading memory usage for decreased processing time. On the other hand, it doesn't *strictly* tell you how many requests came in the last X seconds -- only how many came since the last time unit started. It's also only reasonable for numbers like you suggested -- Tim or Yoav's suggestions would be better if your range is 5 seconds to 60 minutes, for example. justin At 07:10 AM 7/29/2004, you wrote: >I need to display on a .jsp page the number of requests for Tomcat in >the past 5 / 10 / 15/ 30 / 45 / 60 seconds. I've already implement a >Filter will count the total number of requests. I did this with a >static int, which is incremented everytime a request comes in. But what >should I do so that I can show number of request over past time >intervals? Since the present time is always changing, "the past n >seconds" is constantly changing also. >Thanks in advance, >Tom ______________________________________________ Justin Ruthenbeck Software Engineer, NextEngine Inc. justinr - AT - nextengine DOT com Confidential. See: http://www.nextengine.com/confidentiality.php ______________________________________________ --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-user-help@jakarta.apache.org