This Programming Compiler allows you to execute code in various programming languages within Docker containers. It supports running code snippets and executing test cases.
- Python
- JavaScript
- Java
- C++
Endpoint: /run
Method: POST
Payload:
{
"language": "python",
"code": "def factorial(n):\n return 1 if n == 0 else n * factorial(n-1)\nn = int(input())\nprint(factorial(n))",
"testCases": [
{ "input": "5", "expectedOutput": "120" },
{ "input": "0", "expectedOutput": "1" },
{ "input": "3", "expectedOutput": "6" }
]
}
Response:
{
"total": 3,
"passed": 3,
"failed": 0,
"totalExecutionTime": 214,
"results": [
{
"input": "5",
"expectedOutput": "120",
"actualOutput": "120",
"success": true,
"error": "",
"executionTime": 101
},
{
"input": "0",
"expectedOutput": "1",
"actualOutput": "1",
"success": true,
"error": "",
"executionTime": 60
},
{
"input": "3",
"expectedOutput": "6",
"actualOutput": "6",
"success": true,
"error": "",
"executionTime": 53
}
]
}
- Install Docker.
- Pull the required Docker images
- Clone the repository.
- Install dependencies:
npm install
- Start the server:
node index.js
- Security: Ensure that the code execution environment is isolated to prevent malicious code from affecting the host system.
- Resource Management: Limit the CPU and memory usage for each container to prevent resource exhaustion.
- Scalability: Implement a mechanism to manage and scale containers based on the load.
- Error Handling: Provide clear and concise error messages for debugging.
- Logging: Maintain logs for each execution for auditing and debugging purposes.
- Use Lightweight Containers: Use lightweight Docker images to reduce startup time and resource usage.
- Auto-Scaling: Implement auto-scaling to dynamically adjust the number of containers based on the load.
- Caching: Cache compiled code and results to avoid redundant computations.
- Resource Limits: Set appropriate resource limits (CPU, memory) for containers to optimize cost and performance.
- Serverless Architecture: Consider using serverless functions (e.g., AWS Lambda) for running short-lived code snippets to reduce costs.
- Load Balancing: Use a load balancer to distribute requests evenly across multiple containers.
- Monitoring: Continuously monitor the system to identify and address performance bottlenecks.
To add support for a new language, update the languages
object in containerManager.js
with the appropriate Docker image, file extension, and commands for compiling and running the code.
For production, consider using a process manager like PM2 to manage the Node.js application and Docker Swarm or Kubernetes for container orchestration.
Ensure that the input data is passed correctly to the container's stdin and consider increasing the resource limits for containers if necessary.
This project is licensed under the MIT License.