With the rapid development of the Internet of Things (IoT), Mobile Edge Com-puting (MEC) technology is shifting computational and storage capabilities fromcentralized clouds to the network edge to meet the low-latency demands ofnumerous emerging applications. However, ensuring quality of service (QoS) formobile users becomes challenging in dense, decentralized wireless communica-tion environments and with limited MEC server storage capacity. Against thisbackground, this paper proposes a collaborative task processing model for mul-tiple ENs based on service placement and formulates a MINLP optimizationproblem aimed at minimizing system latency and cost. To address this problem,we introduce an online optimization algorithm (OPDA) based on the Lyapunovframework which operates in real-time without the need to predict future infor-mation. Subsequently, we decompose the long-term optimization problem into aseries of one-time slot problems and design a two-stage one-time slot optimiza-tion algorithm to obtain an approximate optimal solution. Specifically, we usethe Lagrange multiplier approach to solve the resource allocation problem fortasks and the matching theory to solve the offloading decision and service place-ment problem for tasks. Simulation results show that our algorithm can achievenear-optimal latency performance while satisfying long-term cost constraints.