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

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.

主站蜘蛛池模板: 雅安市| 宣城市| 广元市| 宣化县| 芦溪县| 峡江县| 金门县| 阜新市| 专栏| 江孜县| 古蔺县| 夏津县| 山阴县| 安顺市| 沙雅县| 三台县| 柳林县| 广汉市| 台北县| 家居| 青阳县| 固始县| 吉安市| 武强县| 永兴县| 鄂伦春自治旗| 深泽县| 禹城市| 都兰县| 沁源县| 西林县| 磐安县| 东海县| 江西省| 平武县| 新余市| 正定县| 津南区| 孟连| 正宁县| 定兴县|