Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a web application requiring a middle-tier language to communicate between an oracle database and math routines on a Linux server and a flex-based application on a client. I'm not a software expert, and need recommendations for which language to use for the middle-tier.

The math routines are currently in Matlab but will be ported to C (or C++) as shared libraries. Thus, by default there's some C or C++ communication necessary. These routines rely on FFTW (www.fftw.org), which is called directly from C or C++ (thus, I don't see re-writing these routines in another language).

The middle tier must manage traffic between the client, the math routines, and the Oracle database. The client will trigger the math routines aynchronously, and the results saved in the db and transferred back to the client, etc. The middle-tier will also need to authenticate user accounts/passwords, and send out various administrative emails.

Originally I thought PhP the obvious choice, but interfacing asychronously multiple clients with the C or C++ routines doesn't seem straightforward. Then I thought, why not just keep the whole middle tier in C or C++, but I'm not sure if this is done in the industry (C or C++ doesn't seem as web-friendly as other languages). There's always Jave + JNI, but maybe that introduces other complications (not sure). Any feedback appreciated.

share|improve this question

migrated from stackoverflow.com Oct 25 '11 at 20:46

6 Answers

in your request, I read

authenticate user accounts/passwords, and send out various administrative emails

So it seems to me that you that what you need is close to a full web app able to call C++ and work asynchronously. Nearly all web frameworks are able to do that.

I suggest two possibilities :

  1. Ruby on Rails with a native interface to C++ and delayed_job
  2. Wt C++ web framework with various libs for delayed jobs and sending emails

Now it's up to you to assess if you only need a very small web app and are able to code it "from scratch" (CGI or mongoose) or if you web app will grow and then you need to learn a new language/framework.

share|improve this answer
+1 for mentioning Ruby; while I don't care for it too much personally, it would seem to be a reasonable possibility for this sort of task. – Donal Fellows Nov 2 '11 at 11:25
I'm committed to Flex/AS3 for the front-end. Looking for back-end language to interface with C or C++ routines for math processing. Correct me if I'm wrong but it seems like I need to jump through a lot of hoops to use PhP to interface with C; what about Ruby, Python, ... ? Any one seem better suited than the others? The ap's needs are not too demanding for back-end other than communicating w/ front end, C/C++ routines, database, apache. – gkdsp Nov 14 '11 at 4:08

I have ran into a similar situation when I wanted to make a web app for exposing large, data intensive computations which would generate neural networks and run sample data through them to see how various algorithms perform. Based on my experience, I think you should break up your app into the following parts:

  • Frontend / Web App
  • Middle Tier / Web Services
  • Backend / Math routines

Frontend / Webapp would consist of the flex app or any other app written in Ruby / Python / Perl / PHP or whatever is your favorite web scripting language. This frontend tier would communicate with your middle tier purely through Web Services - REST / SOAP - take your pick.

The Middle Tier would consist of Web Services written in Java using something like Jersey (or whatever Java Web Services framework you'd like - take your pick). The data access & authentication can be done easily using Java's plethora of data access frameworks. This middle tier can talk to the 'compute' Backend using:

  1. JNI
  2. RPC / thrift / avro or whatever.

The backend could be written in pure C and then wrapped in JNI or it would expose it's functionality using an RPC mechanism - xmlrpc, thrift, avro, protocol buffers etc.

If you decide to take the JNI route then you can implement Queuing, Backgrounding of task extremely easily using Java threads / ExecutorService etc. Also, you would not have to talk to Oracle natively through C/C++ because you can always use Java for data access while the C/C++ library only processes it. But JNI is prone to issues since it's talking to C/C++ code which when not written correctly can lead to coredumps or memory leaks and make your application unstable.

If you decide to take the RPC route then you possibly CAN cut out the Java Middle Tier in which case your entire MT & BE would be written in C/C++. If that's the case I would expect that you'd use probably expose your webservices by writing them as Apache DSOs. AND you'll have to write your own backgrounding / queuing mechanism. This is the harder, less maintainable route IMHO.

Also, the advantage of dividing up your app into these layers gives you great control over replacing your FE / MT without really bothering to replace your BE which is great when you decide you'd like to use Scala instead of Java or you'd like to create an iPhone / iPad / Android / WebOS app - you can reuse your webservices - yay! ;)

share|improve this answer
Thanks, my app requirements are the same as yours. I've divided it up into FE, MT, and BE. My question is which language to use for MT? Java talking to C++ using JNI seems not so robust. Using C/C++ as MT seems too complex. Any other options you'd recommend? – gkdsp Nov 19 '11 at 17:42
1  
As I mentioned in my original answer, you can always go the Java <-RPC-> C/C++ route. This is a robust and extensible solution. Infact, you can bypass the whole Java layer but I would not recommend it as, you'd have to write all sorts of APIs in C/C++ which is not fun to do. Java can save you a lot of time on APIs that derive on top of the C/C++ APIs. Also, don't be afraid of using JNI. JNI is 'fragile' only if the underlying C/C++ code is written in a bad, incomprehensible and buggy way. – void_ptr Nov 20 '11 at 20:18
Thanks for clarifying. – gkdsp Nov 22 '11 at 23:41
makes sense, but if your back-end stuff is C++, you might as well use a C++ web framework (like cppCMS or ATLServer)(or just implement web services using gsoap) for your middletier, which would not increase complexity, but would make maintenance easier - as you'd have 2 languages instead of 3 to manage. – gbjbaanb Apr 27 '12 at 23:46

You could use PHP+Extensions in C (for the math routines). It is not easy but it is feasible.

share|improve this answer

you could consider CGI technology . it allows you to use C/C++ on server side code.

share|improve this answer
Thanks Othman, can you describe this more (how it creates a solution)? Sounds interesting. – ggkmath Oct 25 '11 at 20:00
I would not recommend this. CGI is the old, bad way to create web-based applications; web frameworks in higher-level languages are preferable in every way, especially since most languages offer interfaces to C code. – syrion Nov 2 '11 at 11:04
@syrion: CGI can actually work very well (on Unix) but it does depend on a whole bunch of other factors. Most webservers aren't good at doing CGI though; the chunkier the server, the worse it does at it. (The cost depends on the memory size of the process, irritatingly.) – Donal Fellows Nov 2 '11 at 11:23
sorry for late response. i suggested CGI because the OP needs a server side language in C/C++. yes CGI is old technology. Today i would recommand using Python with a good Python framework like Djongo .then you can easily interface Python with other C/C++ libraries. see python.org – othman Nov 3 '11 at 1:35
if you are interested in CGI have a look at this good book : oreilly.com/openbook/cgi – othman Nov 3 '11 at 1:43
show 2 more comments

I would suggest using node.js. Because of the fast implementation of it's asynchronous APIs, it is perfect as a middle tier. One can also extend node.js with C++, however the execution model in node.js is single threaded, so you should always make such extensions asynchronous. Alternatively you can just launch a C++ process and communicate with it over stdin/stdout with some lightweight protocol.

share|improve this answer
node.js is indeed a very promising technology, but using it in production at the current time (2011/11) seems rather adventurous to me. (I'll wait one year for it to stabilize) – Offirmo Nov 2 '11 at 13:26
@Offirmo: We are using it as a TCP-gateway for an MMORPG. There have been no problems thus far, with up to 2000 concurrent users. PHP and MySQL have both proven less reliable. – back2dos Nov 2 '11 at 13:36
cool ! I'll have a look. By "stability", I referred rather to API and usage stability, i.e. not big parts of the framework changing at each version (like earlier revisions of Ruby on Rails). – Offirmo Nov 2 '11 at 16:12

Best use case for ffead-cpp, provides embedded web server and the web application code resides in a shared library just as your requirement specifies. You should definitely give it a try.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.