Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Threads and Load Balance

Reply
Thread Tools

Threads and Load Balance

 
 
Bob Rivers
Guest
Posts: n/a
 
      12-15-2003
Hi,

We have a web application and due to the heavy traffic, my company
decided to put it under a load balance structure.

We are thinking about the usage of a "standard" load balance
structure:

Load Balancer
|
----------
| |
Server1 Server 2

I was doing some research, and I found some interesting solucions,
like the one described at
http://jakarta.apache.org/tomcat/tom...ter-howto.html.

But none of these solutions talk about threads. Into the jakarta
solution, they describe session replication. And what about threads?

My problem is that I have a thread that continuosly monitors a
database. If this monitor finds something (ie, the due date of an
order) it sends an email.

The problem is that this thread is (I think) attached to the web
server. If I have 2 (or more) servers, this thread will be started
twice, and someone will receive two emails....

So, how do I do threads under a load balance schema?

I am using simple servlets (with J2SE 1.3.1). The server that we are
using is tomcat 4.1.29.

TIA,

Bob
 
Reply With Quote
 
 
 
 
Andy Fish
Guest
Posts: n/a
 
      12-15-2003
obvious solutions would be:

(a) have the emailer thread run in a separate JRE not on the web server.

(b) use some kind of locking mechanism to ensure that only 1 web server is
trying to send emails e.g. have a table in the database which both servlets
will try to insert the same key value into. whoever succeeds gets the right
to send emails. The problem with this one is that you need to coordinate
startup/shutdown and possibly timeouts if one server crashes.

(c) have a status on the order table that says whether an email has been
sent. that way, whichever thread picks up the order first will send the
email. This is quite resilient but may mean extra work in your application.

"Bob Rivers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> We have a web application and due to the heavy traffic, my company
> decided to put it under a load balance structure.
>
> We are thinking about the usage of a "standard" load balance
> structure:
>
> Load Balancer
> |
> ----------
> | |
> Server1 Server 2
>
> I was doing some research, and I found some interesting solucions,
> like the one described at
> http://jakarta.apache.org/tomcat/tom...ter-howto.html.
>
> But none of these solutions talk about threads. Into the jakarta
> solution, they describe session replication. And what about threads?
>
> My problem is that I have a thread that continuosly monitors a
> database. If this monitor finds something (ie, the due date of an
> order) it sends an email.
>
> The problem is that this thread is (I think) attached to the web
> server. If I have 2 (or more) servers, this thread will be started
> twice, and someone will receive two emails....
>
> So, how do I do threads under a load balance schema?
>
> I am using simple servlets (with J2SE 1.3.1). The server that we are
> using is tomcat 4.1.29.
>
> TIA,
>
> Bob



 
Reply With Quote
 
 
 
 
Hylander
Guest
Posts: n/a
 
      12-16-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (Bob Rivers) wrote in message news:<(E-Mail Removed). com>...
> Hi,
>
> We have a web application and due to the heavy traffic, my company
> decided to put it under a load balance structure.
>
> We are thinking about the usage of a "standard" load balance
> structure:
>
> Load Balancer
> |
> ----------
> | |
> Server1 Server 2
>
> I was doing some research, and I found some interesting solucions,
> like the one described at
> http://jakarta.apache.org/tomcat/tom...ter-howto.html.
>
> But none of these solutions talk about threads. Into the jakarta
> solution, they describe session replication. And what about threads?
>
> My problem is that I have a thread that continuosly monitors a
> database. If this monitor finds something (ie, the due date of an
> order) it sends an email.
>
> The problem is that this thread is (I think) attached to the web
> server. If I have 2 (or more) servers, this thread will be started
> twice, and someone will receive two emails....
>
> So, how do I do threads under a load balance schema?


Probably programmatically use messages between servers to control
threads/start/check on threads. Perhaps designate one server as a
master in terms of thread control. You'll have a few cases to deal
with. ie: force one thread to take over if a failover situation
arises. Start up, (if one is down, what to do), if both are up, decide
which one starts and which one sleeps.

Messages of course can be done in a variety of ways....ie: plain
sockets, rmi, java's messaging APIs/message driven ejbs, etc etc. the
other post had some good ideas too. I'd try something simple and then
go from there. Anyone see anything wrong with this approach? (doing
your own threading is not kosher in EJBs btw but it doesn't mean you
can't hack it given you know your implementation and don't mind the
potential drawbacks...some might be serious enough to avoid such
things. you could try to do something more along the lines of a plain
message driven system. Your requirements might vary from what I'm
thinking too....some people want preemptive abilities/realtiming....in
which case, you might want to check if your OS supports it or has a
modified kernel available.)

> I am using simple servlets (with J2SE 1.3.1). The server that we are
> using is tomcat 4.1.29.
>
> TIA,
>
> Bob

 
Reply With Quote
 
Jared Dykstra
Guest
Posts: n/a
 
      12-18-2003
"Andy Fish" <(E-Mail Removed)> wrote in message news:<uZoDb.6503$(E-Mail Removed)>...
> obvious solutions would be:
>
> (a) have the emailer thread run in a separate JRE not on the web server.
>
> (b) use some kind of locking mechanism to ensure that only 1 web server is
> trying to send emails e.g. have a table in the database which both servlets
> will try to insert the same key value into. whoever succeeds gets the right
> to send emails. The problem with this one is that you need to coordinate
> startup/shutdown and possibly timeouts if one server crashes.
>
> (c) have a status on the order table that says whether an email has been
> sent. that way, whichever thread picks up the order first will send the
> email. This is quite resilient but may mean extra work in your application.



No matter what, you're going to have to separate this process from
your servlet. If you stop and think about it, it really doesn't make
sense for a servlet to be more concerned about changes to a database
than incoming web traffic.

Solutions (b) and (c) above will both sort-of work, except leave the
door wide open to a classic race condition. The simplest solution is
to simply go with (a) and write something else to handle
notifications.

I assume a servlet is responsible for changes to the database. If
certain page requests always preceed the database change you're
looking for, have the servlet check to see if an email is required as
the last thing. The request will only go to one server so you don't
have to worry about duplication in this case.

If you are using a database that supports triggers, then use them.
Rather than poll your database server continuiously, let it notify you
when something important happens.

---
Jared Dykstra
http://www.bork.org/~jared
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      12-18-2003
On 18 Dec 2003 00:20:07 -0800, (E-Mail Removed) (Jared Dykstra)
wrote or quoted :

>Jared Dykstra


By any chance are you related to THE Edsger Dykstra?

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Jared Dykstra
Guest
Posts: n/a
 
      12-18-2003
Roedy Green <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> On 18 Dec 2003 00:20:07 -0800, (E-Mail Removed) (Jared Dykstra)
> wrote or quoted :
>
> >Jared Dykstra

>
> By any chance are you related to THE Edsger Dykstra?


LOL, I didn't know my message was *that* profound

---
Jared Dykstra
http://www.bork.org/~jared
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Life Balance Coaching: Balance Work And Life Like A Pro 88059355 Digital Photography 1 01-06-2008 07:32 PM
4840G Load Balance Switch and IIS Question root Cisco 1 11-30-2004 06:13 PM
Layer 4 Switch and Server Load Balance Device Michael Cisco 1 06-09-2004 05:34 AM
Affects of a PL filter on white balance and white balance (D100) jeff liss Digital Photography 1 09-05-2003 02:07 PM
Failover and Load Balance Solution Michael Shiah Cisco 2 07-09-2003 04:51 AM



Advertisments