1

I am currently working on project that is make a online judging system like codeforces. In this system user can submit code and the system will compile, execute, and generate output on a specific input set, and match the output with system result then give verdict.

There is a two part of that system. Front end is in PHP and the backend is in Java. I am responsible for the Java part. My first approach was to make web app. PHP send a http request to Java which file is to compile and execute. But after a certain time I realized that If I compile and execute whenever the request arrive then the system will become too slow. If there is like 300 requests at a time arrive then the system will collapse. My thought was 300 requests handle by 300 threads. But every thread doing a heavy work like compiling, executing and also checking the output.

Then I was writing a standalone java program that has a scheduler. This scheduler check the database, get the new data and compile, execute it and then update and database. This make system asynchronous.

But the problem is in second approach, PHP and Java both need to maintain same entity class(I am using Hibernate). This make the system highly coupled. Whenever PHP making a change, I have to bring change my class also.

What would be the design for this type of application.

Thank you. :)

2

When receiving the http request, you can generate an id for the task and send it back to the client.

Then at the same time, submit a task to a ThreadPoolExecutor. This task can do the compiling and when done save the results against the generated id. The thread pool can run the tasks in the background and stop too many running at the same time.

The client can request the results or check their status by sending the id in another request.

  • thanks for the reply. Is it legitimate creating thread within a container ? – Muztaba Hasanat Aug 21 '16 at 20:19
  • @seal It does go against the Java EE specs. In that case, you can use a ManagedExecutorService instead. – fgb Aug 21 '16 at 22:17
-1

Why not let php send request and keep multi threaded model while each thread just creates a batch job for backend (Java) app for asynchronous execution. So, u have best of both worlds, decoupling and fast response. I guess Jenkins use similar model check it for more hints

  • 1
    Thanks for reply. Could you elaborate what is do you mean by while each thread just creates a batch job for backend (Java) app for asynchronous execution. – Muztaba Hasanat Aug 20 '16 at 20:34
  • What I meant was is that backend Java app has one synchronous and one asynchronous part. Synchronous part accepts the request and creates database entry. Asynchronous part reads the database and processes it. – Varun Mishra Aug 21 '16 at 4:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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