Table of contents
2. Development environment and technology
1. Project introduction
This project is based on load balancing online oj, simulating an online question judging system written by the usual question writing websites (leetcode and Niuke)
The project is mainly divided into five modules:
- Compile and run module: a code processing server built based on the httplib library to test the code submitted by the user
- Business logic module: Build an oj server based on the httplib library and combined with the MVC pattern framework. It is responsible for question acquisition, web page rendering and load balancing, and sends user-submitted codes to the code processing server for processing.
- Data management module: Manage user data and question data based on MySQL database
- Session module: Create a unique session ID for logged in users based on cookies and sessions, and return it to the browser through cookies
- Public module: Contains third-party libraries needed for the entire project and functions of self-written tool classes
2. Development environment and technology
Development environment:
- Lightweight application server (CentOS7.6), gcc/g++, VsCode, MySQL Workbench, Postman, Xshell 7
Main technique:
- C++ STL standard library
- C++ Boost quasi-standard library
- cpp-httplib third-party open source network library
- jsoncpp third-party open source serialization and deserialization library
- ctemplate third-party open source front-end web rendering library
- MVC pattern framework
- Load balancing design
- html、css、js、jquery、ajax
- MySQL C Connect
3. Outline design
This project decouples the code processing function from the main function, and implements the code processing server and the main server respectively, thereby reducing the pressure on each server. The relationship between the server cluster and the browser belongs to the BS architecture. From an analytical perspective, the relationship between the code processing server cluster and the main server belongs to the CS architecture (the main server can be regarded as the client of the code processing server)
The main server function is relatively complex and adopts the MVC pattern framework. The Model layer is responsible for interacting with the database layer, the View layer handles the rendering of web resources, and the Controller controller is responsible for coordinating interactions between various modules. The main server is not a reverse proxy server (it also has other functions besides distribution), but it functions as a reverse proxy and interacts with the code processing server cluster through the load balancing module.
The code processing server is more lightweight than the main server. It mainly has two functions: compilation and operation. It does not interact directly with the browser and delivers all data generated during compilation and operation to the main server for processing.
4. Key Algorithm
The main server uses the minimum number of connections method when sending requests to the code processing server.
The minimum number of connections algorithm is more flexible and intelligent. Since the configuration of the back-end servers is different, the processing of requests may be faster or slower. This algorithm dynamically selects the one with the smallest number of current load connections based on the current connection status of the back-end servers. Each server is used to handle the current request, to improve the utilization efficiency of back-end services as much as possible, and to reasonably distribute the responsibility to each server.
After the user logs in, the MD5 algorithm is used to form the SessionID, thereby realizing the login-free function.
No matter how long the string is, the calculated MD5 value is a fixed length (16-byte version or 32-byte version). As long as the source string changes a little, the final MD5 value will be very different. It is easy to generate MD5 from the source string, but it is theoretically impossible to restore the original string through MD5, making it more private.
5. Project Demonstration
Ordinary user login interface
After successful login, you will get the main interface
The Session Id returned by the server is stored in the browser's Cookie file.
Question list
single question
What happens when you submit your code
job listing
single position
Administrator account login interface
After successful login, enter the administrator interface
Enter the question recording module and enter the question catalog
Enter the position module and enter the position