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

Introduction

Abstraction can protect a database from even the busiest platform. At the time of writing this book, applications and web services often involve hundreds of servers. If we follow a simple and na?ve development cycle where applications have direct access to the database, each of these servers may require dozens of connections per program, even with a small server pool that can result in hundreds or thousands of direct connections to the database. Is this what we want? Consider the scenario illustrated in the following diagram:

We need a way to avoid overwhelming the database with the needs of too many clients. As we suggested in the previous chapter, a PostgreSQL server experiences its best performance when the amount of active connections is less than three times the available CPU count. With a thousand incoming client connections, we will need hundreds of CPU cores to satisfy the formula.

Every incoming connection requires resources such as memory for query calculations and results, file-handle and port allocations for network traffic, process management, and so on. In addition, each connection is another process the OS has to schedule for CPU time. Very large servers are extremely capable, but resources are not infinite. Even if the database can handle thousands of connections, performance will suffer for each in excess of design capacity. We need to change the map to something slightly different, as seen here:

By inserting a connection pool in front of the database, hundreds of PostgreSQL server processes are reduced to dozens. A database pool works by recycling database connections as soon as the client completes its current transaction or when its database work is complete. Instead of hundreds of mostly idle database connections, we maintain a specific set of highly active connections.

Two popular tools for PostgreSQL that provide pooling capability are pgBouncer and pgpool. In this chapter, we will explore how to use these services properly and reduce overhead and database availability.

主站蜘蛛池模板: 临夏县| 客服| 武夷山市| 东乡族自治县| 平遥县| 永寿县| 雅安市| 寻乌县| 襄汾县| 北辰区| 聂拉木县| 团风县| 溧阳市| 镇雄县| 南昌市| 甘孜县| 青田县| 黑水县| 吉水县| 吴旗县| 讷河市| 张家界市| 东乌珠穆沁旗| 财经| 天长市| 邓州市| 清远市| 连南| 石楼县| 安远县| 临高县| 砚山县| 板桥市| 竹溪县| 黄陵县| 永善县| 樟树市| 鄂托克旗| 新竹县| 水城县| 防城港市|