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

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.

主站蜘蛛池模板: 庆阳市| 区。| 荣成市| 龙陵县| 乐清市| 巍山| 南澳县| 棋牌| 仁怀市| 龙南县| 怀柔区| 荆州市| 柞水县| 台北县| 佳木斯市| 万山特区| 工布江达县| 宁德市| 丹巴县| 方山县| 清丰县| 奉节县| 蒲江县| 驻马店市| 察雅县| 西吉县| 咸宁市| 钦州市| 达日县| 永胜县| 海盐县| 若羌县| 贵定县| 防城港市| 乌拉特中旗| 五常市| 合水县| 靖西县| 高邑县| 米泉市| 永嘉县|