We are trying to build a java code compiler to create online coding tests. We are posting the source code through REST API to an endpoint. Next, we are compiling and executing the output against test files then returning results back to the client.
The challenge here is we are spinning up a process javac - compile code and java - execute code on every request which actually takes 30MB of RAM and 600 ms for every process.
This is very huge we are unable to handle the load of 1000 users on octa-core and 16GB RAM. If We get 200 requests at once, it is spawning 200 process which is heavy and other requests are queued up.
The solutions we can think of
- Don't launch
javacevery time, reuse it but how (javac kills itself once compilation is done)? javacshould compile string input rather than from a file.
We are just curious how does the online coding competition platforms solve these problems? We are targeting only for Java. Any help is greatly appreciated.
https://www.journaldev.com/937/compile-run-java-program-another-java-program
.javafiles in response?javacneeds file input.