With the expansion of district heating system, the optimization of hydraulic balance for secondary pipe network has become more complicated, which has brought challenges and inconveniences to large-scale mathematical programming in centralized computing environment. Therefore, a hybrid optimization algorithm under distributed architecture is proposed to solve the optimization of valve opening and parallel pump speed for secondary pipe network. Firstly, the optimization of hydraulic balance of secondary pipe network is divided into two sub-problems, the optimization of valve opening at the building entrance and the optimization of the parallel pump speed of the heat exchange station. Secondly, according to the prediction results of heating load of each building in the district, taking the minimum impedance of the secondary pipe network as the target and the thermal load demand of each end-user as the constraint, the dynamic hydraulic balance optimization model of the pipe network is established. Then, based on the distributed architecture, an improved distribution-sine cosine algorithm-fruit fly optimization algorithm (D-SCAFOA) is proposed, which retains the framework of fruit fly optimization algorithm (FOA), and adopts the strategy of sines and cosines algorithm (SCA) to replace the random strategy of FOA algorithm in the olfactory search stage. Finally, two real engineering cases of district heating system are given to verify the effectiveness of the proposed framework and method. The results results show that compared with the traditional centralized computing method, the optimal control method under the distributed architecture can solve the problem of on-demand heating of the secondary pipe network in the district heating system under the fast convergence speed, and the energy consumption of transmission and distribution are low.