473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Suggestion

I have Windows Service application which creates reports. It's a
multithreaded application which scans database every several seconds and
retrieves records from a database and than spans a new thread for each
record which creates a report. I run this application on 3 different
servers and each server does a specific type of records. What I would like
to do is to have all servers processing any type of record, but I want only
one program processing any one record. My question is how do I keep
multiple servers from processing the same records. I've tried to place a
flag in the database as 1 = processing and 0 = is not, but database it not
fast enough, caching on the database prevents reading of the latest status.
How do I communicate between all servers. I am not looking for specific
code just an idea or pointers on how to communicate between all servers
before processing a record. I don't want to have a master server because
it's a one point of failure.
Thank You
Peter
Aug 12 '08 #1
10 1070
On Tue, 12 Aug 2008 00:00:51 -0500, Peter wrote:

I keep multiple servers from processing the same records. I've tried to
place a flag in the database as 1 = processing and 0 = is not, but
database it not fast enough, caching on the database prevents reading of
the latest status. How do I communicate between all servers. I am not
looking for specific code just an idea or pointers on how to communicate
between all servers before processing a record. I don't want to have a
master server because it's a one point of failure.

Implement a socket server that monitors the database and hands out the
identifiers to the clients. Clients start and connect to find out next
record, if there is none then the server blocks the client reports until
there is something to do. You can start as many clients as you want and
all the server does is monitor the database and cycle through the queue
of requests handing them out to work.

Ken
Aug 12 '08 #2
Thanks Ken for your help!

But if the socket server goes down all of the clients are down - single
point of failure.
"Ken Foskey" <rm**********@optushome.com.auwrote in message
news:48********@dnews.tpgi.com.au...
On Tue, 12 Aug 2008 00:00:51 -0500, Peter wrote:

>I keep multiple servers from processing the same records. I've tried to
place a flag in the database as 1 = processing and 0 = is not, but
database it not fast enough, caching on the database prevents reading of
the latest status. How do I communicate between all servers. I am not
looking for specific code just an idea or pointers on how to communicate
between all servers before processing a record. I don't want to have a
master server because it's a one point of failure.


Implement a socket server that monitors the database and hands out the
identifiers to the clients. Clients start and connect to find out next
record, if there is none then the server blocks the client reports until
there is something to do. You can start as many clients as you want and
all the server does is monitor the database and cycle through the queue
of requests handing them out to work.

Ken

Aug 12 '08 #3
On Tue, 12 Aug 2008 00:32:49 -0500, Peter wrote:
Thanks Ken for your help!

But if the socket server goes down all of the clients are down - single
point of failure.
Use UDP and a broadcast, have all clients monitor the same UDP
broadcast socket. No lag time. Each one advertises which ones they pick
up.

Servers should advertise completed ones. If there is no completed and a
server is idle it should query old incomplete jobs using the same
broadcast and if there is no response pick that one up and start working
on it again (recoverability).

Note that UDP is not reliable and two could start work on exactly the
same piece at the same time. So you have to handle conflicts still, it
just reduces the probability.

I am wondering how you don't have a central point of failure with a
Database anyway?

Ken
Aug 12 '08 #4
On Mon, 11 Aug 2008 22:32:49 -0700, Peter <cz****@nospam.nospamwrote:
Thanks Ken for your help!

But if the socket server goes down all of the clients are down - single
point of failure.
I understand your desire to not have a single point of failure. But
distributing the logic to deal with coordinating processing amongst all
the peers could be very costly network-wise. For example, an alternative
solution would be for each server running to query the others to see if
they've processed a given record yet. But as the numebr of servers goes
up, the network traffic to support that goes up dramatically.

I think that at some point, you may need a central repository for the
information related to distributing the work.

Now, that said, that doesn't mean you have to live without redundancy.
For example, one reasonably common technique is to design your servers to
nominate a central manager, either to farm out the work, or simply to
track which data has been processed by a server already. Either way, each
of the other servers would communicate with that central manager server to
figure out what work to do.

If the server acting as central manager went offline for some reason, the
remaining servers could detect that and elect a new central manager.

So, that's a complicated suggestion. Here's a simple one: if your
database has some inherent ordering of the records, then perhaps a more
appropriate solution would be to assign each server some pre-defined
subset of records. For example, one server could handle the first third
of the database, another the second third, and the third the last third.
Or, one server could handle the 0th, 3rd, 6rd, etc., another the 1st, 4th,
7th, etc. and so on. Or you could blend the two and have one server
handle the 0th, 3rd, 6th, etc. N records (e.g. if N is 10, then that
server handles records 0-9, 30-39, 60-69, etc.), etc.

The simple approach runs the risk of one server completing early and
winding up idle for part of the time. But assuming that the records all
take about the same time to process, or at least are randomly distributed
with respect to their cost to process, any large set of data should result
in a reasonably uniformly distributed workload for your servers.

I seem to recall some work being done on clustered Windows servers. It's
possible that all of the above is pointless, and that there's already some
sort of API or framework on Windows that allows you to run multiple,
identical servers and where Windows itself handles distributing the work
evenly, in a failure-resistant manner. You might try Googling on that and
see what you come up with. I did a quick search and turned up this:
http://www.microsoft.com/windowsserv...rview/san.mspx
It wasn't clear to me at first glance whether that's something appropriate
to your needs (it's possible that all that does is provide for
functionally identical servers to be allocated dynamically to independent
client requests), but it's worth a look I think.

One last note: you mentioned in your original post that you start a new
thread for each record. I don't think that's a great approach, unless
you've got a custom thread pool and you limit its size to the number of
CPUs on the computer. You definitely don't want more threads running than
you have CPUs, and ideally you won't have fewer either. But either way,
this means you should be managing your threads according to the workload
the computer is capable of, not just arbitrarily creating a new thread for
each record.

Pete
Aug 12 '08 #5
How are you handling redundancy on the database? This mechanism could
also handle switch over to a redundant data manager. If you don't have a
redundant database then you already have a single point of failure and
the whole topic is mute.
Peter wrote:
Thanks Ken for your help!

But if the socket server goes down all of the clients are down - single
point of failure.
"Ken Foskey" <rm**********@optushome.com.auwrote in message
news:48********@dnews.tpgi.com.au...
>On Tue, 12 Aug 2008 00:00:51 -0500, Peter wrote:

>>I keep multiple servers from processing the same records. I've tried to
place a flag in the database as 1 = processing and 0 = is not, but
database it not fast enough, caching on the database prevents reading of
the latest status. How do I communicate between all servers. I am not
looking for specific code just an idea or pointers on how to communicate
between all servers before processing a record. I don't want to have a
master server because it's a one point of failure.

Implement a socket server that monitors the database and hands out the
identifiers to the clients. Clients start and connect to find out next
record, if there is none then the server blocks the client reports until
there is something to do. You can start as many clients as you want and
all the server does is monitor the database and cycle through the queue
of requests handing them out to work.

Ken

Aug 12 '08 #6
DB is not fast enough?

01: Select all rows with state = 0

02:

while (move to next row)
{
try
{
start transaction
update the status to 01
commit transaction
process it
}
catch (the optimistic locking exception you experience)
{
roll back transaction
}
}

Pete
Aug 12 '08 #7
Thanks Peter - you have convinced me!

I do have a thread pool, but it's more than number of CPUs, the reason for
that is this program runs Crystal Reports, the reports access DB2 database
on AIX server, one report can take few seconds to retreive data and next one
could take few minutes, the CPU is idle when Crystal Reports is retreiving
the data. I agree the program should manage the threads based on the
workload, but in this case it's impossible. For example the program starts a
thread and asks database for the data, when this occurs the CPU drops down
almost to zero, so my program looks at the CPU and says there is still
plenty of CPU so I will span another thread, and so on and so on, then each
thread returns data from the database and CPU goes up 100%. Same thing
could happen the other way, my program looks at the CPU and it's at 100% so
it would not span anymore threads, but it could be spanning new threads
because it takes few seconds to retreive data from the database.

"Peter Duniho" <Np*********@nnowslpianmk.comwrote in message
news:op***************@petes-computer.local...
On Mon, 11 Aug 2008 22:32:49 -0700, Peter <cz****@nospam.nospamwrote:
>Thanks Ken for your help!

But if the socket server goes down all of the clients are down - single
point of failure.

I understand your desire to not have a single point of failure. But
distributing the logic to deal with coordinating processing amongst all
the peers could be very costly network-wise. For example, an alternative
solution would be for each server running to query the others to see if
they've processed a given record yet. But as the numebr of servers goes
up, the network traffic to support that goes up dramatically.

I think that at some point, you may need a central repository for the
information related to distributing the work.

Now, that said, that doesn't mean you have to live without redundancy.
For example, one reasonably common technique is to design your servers to
nominate a central manager, either to farm out the work, or simply to
track which data has been processed by a server already. Either way, each
of the other servers would communicate with that central manager server to
figure out what work to do.

If the server acting as central manager went offline for some reason, the
remaining servers could detect that and elect a new central manager.

So, that's a complicated suggestion. Here's a simple one: if your
database has some inherent ordering of the records, then perhaps a more
appropriate solution would be to assign each server some pre-defined
subset of records. For example, one server could handle the first third
of the database, another the second third, and the third the last third.
Or, one server could handle the 0th, 3rd, 6rd, etc., another the 1st, 4th,
7th, etc. and so on. Or you could blend the two and have one server
handle the 0th, 3rd, 6th, etc. N records (e.g. if N is 10, then that
server handles records 0-9, 30-39, 60-69, etc.), etc.

The simple approach runs the risk of one server completing early and
winding up idle for part of the time. But assuming that the records all
take about the same time to process, or at least are randomly distributed
with respect to their cost to process, any large set of data should result
in a reasonably uniformly distributed workload for your servers.

I seem to recall some work being done on clustered Windows servers. It's
possible that all of the above is pointless, and that there's already some
sort of API or framework on Windows that allows you to run multiple,
identical servers and where Windows itself handles distributing the work
evenly, in a failure-resistant manner. You might try Googling on that and
see what you come up with. I did a quick search and turned up this:
http://www.microsoft.com/windowsserv...rview/san.mspx
It wasn't clear to me at first glance whether that's something appropriate
to your needs (it's possible that all that does is provide for
functionally identical servers to be allocated dynamically to independent
client requests), but it's worth a look I think.

One last note: you mentioned in your original post that you start a new
thread for each record. I don't think that's a great approach, unless
you've got a custom thread pool and you limit its size to the number of
CPUs on the computer. You definitely don't want more threads running than
you have CPUs, and ideally you won't have fewer either. But either way,
this means you should be managing your threads according to the workload
the computer is capable of, not just arbitrarily creating a new thread for
each record.

Pete

Aug 12 '08 #8
I really don't care if the database is point of failure, if database is down
the whole company is down, if my program is down users are screaming
"where's my report!" - It's kind of like we don't carry a spare engine, but
we do carry spare tire and the engine is a single point of failure so why do
we carry the spare tire.

I don't need redundancy in a true sense "if one process goes down there's
another one waiting in the wings", what I need is multiple programs
processing data from the same pool, if one goes down the process is still
continuing, although slower and also ability to add more servers to the pool
if need arises.

Thanks Lean for pointing the possible problems, I do appreciate it - it
makes you think.
"Leon Lambert" <la******@inil.comwrote in message
news:uN**************@TK2MSFTNGP02.phx.gbl...
How are you handling redundancy on the database? This mechanism could also
handle switch over to a redundant data manager. If you don't have a
redundant database then you already have a single point of failure and the
whole topic is mute.
Peter wrote:
>Thanks Ken for your help!

But if the socket server goes down all of the clients are down - single
point of failure.
"Ken Foskey" <rm**********@optushome.com.auwrote in message
news:48********@dnews.tpgi.com.au...
>>On Tue, 12 Aug 2008 00:00:51 -0500, Peter wrote:
I keep multiple servers from processing the same records. I've tried to
place a flag in the database as 1 = processing and 0 = is not, but
database it not fast enough, caching on the database prevents reading
of
the latest status. How do I communicate between all servers. I am not
looking for specific code just an idea or pointers on how to
communicate
between all servers before processing a record. I don't want to have a
master server because it's a one point of failure.

Implement a socket server that monitors the database and hands out the
identifiers to the clients. Clients start and connect to find out next
record, if there is none then the server blocks the client reports until
there is something to do. You can start as many clients as you want and
all the server does is monitor the database and cycle through the queue
of requests handing them out to work.

Ken
Aug 12 '08 #9
Thanks Ken for your advice I think I'll go with your suggestion.

I don't want to overstay my welcome, but do you know of any source code
examples or reading material?

Yes database is a single point of failure, but that's not relevant in my
case, if the database goes down the whole company is down, if my program
goes down the users will be screaming "where is my report!", so I have to
take care of my piece of process first.
"Ken Foskey" <rm**********@optushome.com.auwrote in message
news:48******@dnews.tpgi.com.au...
On Tue, 12 Aug 2008 00:32:49 -0500, Peter wrote:
>Thanks Ken for your help!

But if the socket server goes down all of the clients are down - single
point of failure.

Use UDP and a broadcast, have all clients monitor the same UDP
broadcast socket. No lag time. Each one advertises which ones they pick
up.

Servers should advertise completed ones. If there is no completed and a
server is idle it should query old incomplete jobs using the same
broadcast and if there is no response pick that one up and start working
on it again (recoverability).

Note that UDP is not reliable and two could start work on exactly the
same piece at the same time. So you have to handle conflicts still, it
just reduces the probability.

I am wondering how you don't have a central point of failure with a
Database anyway?

Ken

Aug 12 '08 #10
On Tue, 12 Aug 2008 08:27:42 -0500, Peter wrote:
Thanks Ken for your advice I think I'll go with your suggestion.

I don't want to overstay my welcome, but do you know of any source code
examples or reading material?
I have something that does the broadcast and another that monitors it.
Unfortunately what I have done is totally different to what you need.

Ken

loose rmove. if you want to go offline.
Aug 13 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: John Wellesz | last post by:
Hello, It would be great if there was an option to tell PHP to let the user manage all the HTTP headers instead of sending what it thinks is good for the programmer... For example when you...
5
by: John | last post by:
Hi: I'd like to implement a simple map, which is a 2-D plane with many points, e.g., 100. The points are not evenly distributed, i.e., some points may have two neighbor points; some may have 5...
10
by: Paulo Jan | last post by:
Hi all: Let's say I'm designing a database (Postgres 7.3) with a list of all email accounts in a certain server: CREATE TABLE emails ( clienteid INT4, direccion VARCHAR(512) PRIMARY KEY,...
7
by: J.Marsch | last post by:
I don't know whether this is the appropriate place to give product feedback, but here goes: I would love to see some kind of diagnostic to let me know when implicit boxing has occurred. We...
2
by: vinay | last post by:
I have a scenario, need your suggestion.. Our clients are already using the forms authentication where we check the User/Pwd from SQL svr Database. We also have some SETTINGS for the user saved...
13
by: sandeep chandra | last post by:
Hey guys, I am new to this group.. i never know wot s going on in this group.. but wot made be brought here is cpp.. guys am currently a part of onw reaserch ... am new to everything.. i...
17
by: Jedrzej Miadowicz | last post by:
I recently (re)discovered data binding in Windows Forms thanks to its advances in Visual Studio 2005. As I looked a little deeper, however, I realize that it still suffers from an irksome tendency...
4
by: John Salerno | last post by:
I apologize for the slightly off-topic nature, but I thought I'd just throw this out there for anyone working on text editors or IDEs with auto-completion. I think it should be a feature, when...
20
by: Allan Ebdrup | last post by:
I have a suggestion for C# I would like reader/writer locks to be built in to the language. When you want to aquire a loct on an object o you write lock(o) { ...//critical region } I would...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.