官术网_书友最值得收藏!

Queueing

In order to avoid overwhelming anyone, we might add a buffer between the clients and the dispatcher. This new worker is responsible for managing customer relations. Instead of speaking directly with the dispatcher, the client speaks to the services manager, passing the manager requests, and at some point in the future, getting a call that their task has been completed. Requests for work are added to a prioritized work queue (a stack of orders with the most important one on top), and this manager waits for another client to walk through the door. 

The following figure describes the situations:

The dispatcher tries to keep all workers busy by pulling tasks from this queue, passing back any packages workers have completed, and generally maintaining a sane work environment where nothing gets dropped or lost. Rather than proceeding task-by-task along a single timeline, multiple simultaneous jobs, on their own timelines, run in parallel. If it comes to a point where all the workers are idle and the task queue is empty, the office can sleep for a while, until the next client arrives.

This is a rough schematic of how Node gains speed by working asynchronously, rather than synchronously. Now, let's pe deeper into how Node's event loop works.

主站蜘蛛池模板: 安远县| 安顺市| 黔南| 安龙县| 田东县| 浏阳市| 定襄县| 沙河市| 托克托县| 攀枝花市| 房山区| 洪泽县| 奉贤区| 谷城县| 义马市| 普定县| 崇仁县| 西林县| 天柱县| 泸西县| 佛坪县| 双柏县| 开平市| 揭西县| 玉树县| 深泽县| 五原县| 呼和浩特市| 静海县| 定结县| 定陶县| 洮南市| 仁怀市| 乌拉特后旗| 治多县| 金山区| 监利县| 汽车| 桦甸市| 饶河县| 吉隆县|