C++ Application Architecture


I'm not sure if I'm posting in the right channel, so apologies if this is the wrong one.

We currently have a quite large application written in C that is a collection of cgi programs that are called through an Apache server via XML.  A client makes a requests on our cgi's, the cgi's perform an operation and then return the result to the client (again in XML).  The C application is a back-end of a web site and has many uses.  We roughly serve about 2,000,000 number of client requests per day, some of the requests are quite resourceful and can take upto 40 seconds to respond to the client.  The C application has many external communication channels that it must communicate with over XML and also has MySQL databases for lookup/storage.

The time has come to re-write the application due to pressure from outside sources not happy about the scalability and that it is using cgi's and no database pooling.

The application will be re-written using C++ and I'm looking at what ways it can be done.  The objective it to make it more scalable and make a persistent framework where each client request is handled by a threaded server so reducing overhead of running a new process.

So far I have come up with the idea that I can write a threaded server using pthreads that will listen on a port, accept new clients and create a new thread to handle that process.  this is obviously a very simple overview of what I want to do but I'd like to know if there is anything else I should like at ?

Our current platform is Redhat Linux, we have 9 application servers, on each server an apache instance runs one any of the cgi's can be called.

Any ideas / suggestions would be very helpful.



Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi Marvin,

C++ is data-centric and C is procedure centric ... Here what you have listed is all procedures. This and my natural affinity for C compels me to recommend optimizing the existing code rather than rewriting it. Rewriting is rarely a sucees story.

That out of the way, yes the ideas you are having are in the right direction ... That very well might be the way to go. There will be some design issues you might need to consider,e.g. max threads at any time, max free threads at any time, min number of threads you would like to pre-spawn so that they are ready to serve when a request arrives, design of a thread manager etc.

Along with that I am sure you will be having some project specific nuances which I am not aware of, but am sure that they are there ;o)

Apache web server is built on similar architecture. A glance through apache documentation should be able to provide some insight.

checkinAuthor Commented:
Ok, thanks for the information.

I agree that a re-write is probably not going to give much benefit, unfortunately the company that we work in does not see that.  The whole company is Java/J2E based and see that our application written in C is a legacy application.  The application is maintained by only 3 people and these people (me being one of them) only have the knowledge of how it does and should work.
The problem we have right now about making it persistence is that over the years of evolution the memory management has been ignored due to processes starting and ending, people got lazy abouting freeing it.  It would take just as long to go through each function and make it release its memory.  Additionally one of the cgi's which is threaded itself is known to do the odd core dump which would be fatal for a persitant server process (I'm sure thats down to a concurrency issue though).

Anyway thanks again for the information, I'll try and find some information on creating a thread manager.

Hi Marvin,

Does your company believe that a rewrite will be bug free? Searching malloc will be easy ... all you need is a grep ... If normal coding procedures have been followed then the functions that mallocs memory should be responsible for freeing it. ... But I feel that pursuing this point has little utility as this decision seems to involve the higher ups.

Thread manager would be custom to your application. You need to figure out the classes and data first (if you are going C++ way) and the interface that each class provides. Thread manager would be realtively simple part which will keep track of all the threads ... the free pool, the busy pool, max threads, min threads etc... How to request a thread for processing a request, how to free a thread and other such isssues might need some thought and might influence the performance and scalability to a certain extent.

Good luck

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.