Re: Best way to log requests from a servlet and to a database?

2013-01-26 Thread Brian Braun
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 than
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?  :-)

On Sat, Jan 26, 2013 at 12:25 AM, Hassan Schroeder 
hassan.schroe...@gmail.com wrote:

 On Fri, Jan 25, 2013 at 8:16 PM, Brian Braun brianbr...@gmail.com wrote:
  OK, Amazon's solution would be too expensive to use as a first option. I
  would like to use it but just after a first queue is full. This first
 queue
  would be something running in my own host, using RAM to host the buffer.
  Any ideas on how to create this?

 Since you already have an implicit interface --

   ...doing a (new Thread(new certain Object)).start();

 write some tests describing the behavior of that class as a resource
 (in this case memory) threshold approaches. The actual design will
 probably be pretty apparent. Or at least you'll have a good start.

 /*  been there, done that, drunk the TDD koolaid  :-)   */
 --
 Hassan Schroeder  hassan.schroe...@gmail.com
 http://about.me/hassanschroeder
 twitter: @hassan

 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org




RE: [OT] Best way to log requests from a servlet and to a database?

2013-01-26 Thread Caldarale, Charles R
 From: Brian Braun [mailto:brianbr...@gmail.com] 
 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 than
 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_ additional 
logging service thread.  When each request processing thread has prepared 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 idle, the request 
processing thread should mark the logging service thread as active and wake it 
up before unlocking the queue; if the logging service thread is already active, 
the request processing thread just unlocks the queue after enqueuing its entry. 
 When the logging service thread wakes up, it must lock the queue, remove _all_ 
the entries currently on the queue, unlock the queue, and send all the removed 
entries to the database in as few calls as possible.  Once that's done, the 
logging service thread relocks the queue, checks for any new arrivals and 
repeats as needed.  If no new arrivals, 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.) for 
all this (safest), or the newer but easier to abuse java.util.concurrent 
operations.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL 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 
attachments from all computers.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Different webapp paths on different hosts

2013-01-26 Thread chris derham

 it's not. maybe it will make things clear if i change the names of the
 paths, say:

 * when user goes to http://app1.com/ - {thesamewebapp}/app1 path is served
 as root path of the domain app1.com
 * when user goes to http://app2.com/ - {thesamewebapp}/app2 path is served
 as root path of the domain app2.com


From this I conclude that the explicit requirement is to have a single
running version of the war, that responds to different domains. You
seem to think that you have an additional implicit requirement that
this must be done within tomcat by having different contexts. This
seems to me to be the source of confusion in all the replies to your
thread.


 What you are trying to do is make the same webapp answer both
 domain1.com/ and domain2.com/ right? If so you can simply
 deploy the webapp as ROOT. The webapp will then answer on all domains
 pointing to the server. If this is not what you want, you
 can set up a virtual host in server.xml with an appbase outside the
 webapps folder (eg. $CATALINA_BASE (or is it HOME?)$\domain1
 and then use the Alias element to specify the second domain as an alias
 for the first (which you set as an attribute in the
 Host element).


 i know these tricks, but they don't work for my case.

To my mind if you deploy the app as ROOT.war, as long as DNS is
configured correctly, that single context will serve responses to
http://app1.com/ and http://app2.com/. This appears solves the
explicit requirement stated above. However you state they don't work
for my case - please explain why this doesn't work for your case

Thanks

Chris

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Different webapp paths on different hosts

2013-01-26 Thread Caldarale, Charles R
 From: cjder...@gmail.com [mailto:cjder...@gmail.com] On Behalf Of chris derham
 Subject: Re: Different webapp paths on different hosts

 To my mind if you deploy the app as ROOT.war, as long as DNS is
 configured correctly, that single context will serve responses to
 http://app1.com/ and http://app2.com/. This appears solves the
 explicit requirement stated above.

Which is what I suggested back on 23 January:
 
 Assuming path1.com and path2.com evaluate to the same IP address (or 
 at least to the same system), this will happen automatically with a 
 single Host element in the Tomcat configuration. 

But the OP refuses to supply any information about why that's not sufficient.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL 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 
attachments from all computers.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Different webapp paths on different hosts

2013-01-26 Thread bxqdev



On 1/26/2013 9:23 PM, chris derham wrote:


it's not. maybe it will make things clear if i change the names of the
paths, say:

* when user goes to http://app1.com/ - {thesamewebapp}/app1 path is served
as root path of the domain app1.com
* when user goes to http://app2.com/ - {thesamewebapp}/app2 path is served
as root path of the domain app2.com



 From this I conclude that the explicit requirement is to have a single
running version of the war, that responds to different domains. You
seem to think that you have an additional implicit requirement that
this must be done within tomcat by having different contexts. This
seems to me to be the source of confusion in all the replies to your
thread.


actually it would only be more convenient to do this with just tomcat.
but i would like to know any methods that solve the problem.





What you are trying to do is make the same webapp answer both
domain1.com/ and domain2.com/ right? If so you can simply
deploy the webapp as ROOT. The webapp will then answer on all domains
pointing to the server. If this is not what you want, you
can set up a virtual host in server.xml with an appbase outside the
webapps folder (eg. $CATALINA_BASE (or is it HOME?)$\domain1
and then use the Alias element to specify the second domain as an alias
for the first (which you set as an attribute in the
Host element).



i know these tricks, but they don't work for my case.


To my mind if you deploy the app as ROOT.war, as long as DNS is
configured correctly, that single context will serve responses to
http://app1.com/ and http://app2.com/. This appears solves the
explicit requirement stated above. However you state they don't work
for my case - please explain why this doesn't work for your case


in this case http://app1.com/ and http://app2.com/ will serve the same content.
i need different content on different domains.



Thanks

Chris

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Different webapp paths on different hosts

2013-01-26 Thread bxqdev



On 1/26/2013 9:36 PM, Caldarale, Charles R wrote:

From: cjder...@gmail.com [mailto:cjder...@gmail.com] On Behalf Of chris derham
Subject: Re: Different webapp paths on different hosts



To my mind if you deploy the app as ROOT.war, as long as DNS is
configured correctly, that single context will serve responses to
http://app1.com/ and http://app2.com/. This appears solves the
explicit requirement stated above.


Which is what I suggested back on 23 January:


Assuming path1.com and path2.com evaluate to the same IP address (or
at least to the same system), this will happen automatically with a
single Host element in the Tomcat configuration.


But the OP refuses to supply any information about why that's not sufficient.

  - Chuck


in this case http://app1.com/ and http://app2.com/ will serve the same content.
i need different content on different domains.




THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL 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 
attachments from all computers.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Different webapp paths on different hosts

2013-01-26 Thread Caldarale, Charles R
 From: bxqdev [mailto:bxq...@themailbay.com] 
 Subject: Re: Different webapp paths on different hosts

 in this case http://app1.com/ and http://app2.com/ will serve the same 
 content.
 i need different content on different domains.

First you state that you want the same webapp to serve both domains, and now 
you state that you want different content for each domain.  If you really want 
to do that, the single webapp will have to decide what content to deliver based 
on the request URL.

If you don't want to put that logic in the webapp, you will need a separate 
webapp for each domain, with a Host element for each domain.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL 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 
attachments from all computers.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: [OT] Best way to log requests from a servlet and to a database?

2013-01-26 Thread Brian Braun
Hi chuck,

I finally found this, implemented it and works great!
http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/LinkedBlockingQueue.html

However, if I get significantly more requests, this may not be enough
because MySQL will get slower and the queue will get full. I think I could
start using this queue, and if it gets full I could failover to Amazons
Queue service. What do you think?



On Sat, Jan 26, 2013 at 9:06 AM, Caldarale, Charles R 
chuck.caldar...@unisys.com wrote:

  From: Brian Braun [mailto:brianbr...@gmail.com]
  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
 than
  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_
 additional logging service thread.  When each request processing thread has
 prepared 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 idle, the request processing thread should mark the logging
 service thread as active and wake it up before unlocking the queue; if the
 logging service thread is already active, the request processing thread
 just unlocks the queue after enqueuing its entry.  When the logging service
 thread wakes up, it must lock the queue, remove _all_ the entries currently
 on the queue, unlock the queue, and send all the removed entries to the
 database in as few calls as possible.  Once that's done, the logging
 service thread relocks the queue, checks for any new arrivals and repeats
 as needed.  If no new arrivals, 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.)
 for all this (safest), or the newer but easier to abuse
 java.util.concurrent operations.

  - Chuck


 THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
 MATERIAL 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 attachments from all computers.


 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: users-h...@tomcat.apache.org




RE: [OT] Best way to log requests from a servlet and to a database?

2013-01-26 Thread Caldarale, Charles R
 From: Brian Braun [mailto:brianbr...@gmail.com] 
 Subject: Re: [OT] Best way to log requests from a servlet and to a database?

 However, if I get significantly more requests, this may not be enough
 because MySQL will get slower and the queue will get full. I think I could
 start using this queue, and if it gets full I could failover to Amazons
 Queue service. What do you think?

I think it would be cheaper for you to just spool the excess logging objects to 
your own local disk if the in-memory queue reaches some predetermined limit.  
However, if your DB server really can't keep up, you'll need some strategy to 
just discard log entries or reject requests until it can, even if you overflow 
to local disk.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 
MATERIAL 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 
attachments from all computers.


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org