The invention discloses a real-time charging optimization method for electric vehicle cluster based on clustering control, and relates to the field of real-time charging in electric vehicle cluster, which comprising the following steps of: step 1, based on a distributed layered control framework, performing a queue division on the EV cluster by taking the charging end time as a judgment amount; step 2, according to the charging characteristics of EV cluster, the queue division of EV cluster is conducted by taking the end of charging as a criterion; step 2, a real-time optimization model of charging and discharging power for EV cluster with the objective of minimizing daily load fluctuation is solved, real-time optimization of charging and discharging power of EV cluster is carried out, andsecurity constraints are checked by distribution network; step 3, on the basis of an EV cluster scheduling result, the charging and discharging costs of EV owners are considered, a power allocation model in EV cluster is solved, the optimal power allocation for charging and discharging power of a single EV in the EV cluster is obtained, so that the total output of the EV cluster is as close as possible to the scheduling result. By means of the device, EV charge and discharge distributed layered control framework is adopted, thereby realizing the real-time control of charging and discharging in EV cluster.