The Electrical Submersible Pump (ESP) which is installed in the oil well is commonly used for oil production. The parameters which can be adjusted on the surface are mainly choke and frequency. The whole closed loop control system consists of down-hole data sampling module, automatic PID control module, data communication and control module. With the wired communication, the ESP system can be controlled and optimized automatically. The analysis and optimization part is mainly responsible for analyzing the real-time working condition of ESP. Under the oil well production constraints and using second order polynomial curve model, the optimal frequency can be determined and the ESP closed loop control will be realized. At the same time, we are able to set up a protection mechanism to prevent the frequent adjustment of ESP. Furthermore, it can effectively prevent the damage of pump and the oil formation. Therefore, it can make sure that the oil production is adjusted automatically according to the real-time liquid supply situations.