暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

PostgreSQL 多线程连接池 - Scalable PostgreSQL connection pooler odyssey

digoal 2019-06-24
608

作者

digoal

日期

2019-06-24

标签

PostgreSQL , 连接池 , 多线程 , odyssey


背景

PostgreSQL 应用最广泛的连接池pgbouncer,是单进程的,但是效率非常高,而且是纯C代码,比较小巧。不过毕竟是单核,扩展性受限,虽然单个进程能处理5万左右QPS。但是超过后就需要扩展,通常可以创建多个PGBOUNCER再使用HAPROXY或LVS做负载均衡,但是使用还是不方便。

pgpool-II是支持读写分离的连接池。虽然是多进程,但是性能损耗较大。作为纯连接池有点吃亏,如果是读写分离可以考虑。

odyssey可以满足纯连接池的需求。多线程,可扩展。

源码:
https://github.com/yandex/odyssey

Odyssey
Advanced multi-threaded PostgreSQL connection pooler and request router.

Project status
Although we run Odyssey in production, the project is currently in Beta. We appreciate any kind of feedback and contribution to the project.

Design goals and main features
Multi-threaded processing
Odyssey can significantly scale processing performance by specifying a number of additional worker threads. Each worker thread is responsible for authentication and proxying client-to-server and server-to-client requests. All worker threads are sharing global server connection pools. Multi-threaded design plays important role in SSL/TLS performance.

Advanced transactional pooling
Odyssey tracks current transaction state and in case of unexpected client disconnection can emit automatic Cancel connection and do Rollback of abandoned transaction, before putting server connection back to the server pool for reuse. Additionally, last server connection owner client is remembered to reduce a need for setting up client options on each client-to-server assignment.

Better pooling control
Odyssey allows to define connection pools as a pair of Database and User. Each defined pool can have separate authentication, pooling mode and limits settings.

Authentication
Odyssey has full-featured SSL/TLS support and common authentication methods like: md5 and clear text both for client and server authentication. Additionally it allows to block each pool user separately.

Logging
Odyssey generates universally unique identifiers uuid for client and server connections. Any log events and client error responses include the id, which then can be used to uniquely identify client and track actions. Odyssey can save log events into log file and using system logger.

Architecture and internals
Odyssey has sophisticated asynchronous multi-threaded architecture which is driven by custom made coroutine engine: machinarium. Main idea behind coroutine design is to make event-driven asynchronous applications to look and feel like being written in synchronous-procedural manner instead of using traditional callback approach.

One of the main goal was to make code base understandable for new developers and to make an architecture easily extensible for future development.

More information: Architecture and internals.

Build instructions
Currently Odyssey runs only on Linux. Supported platforms are x86/x86_64.

To build you will need:

  • cmake >= 2.8
  • gcc >= 4.6
  • openssl

git clone git://github.com/yandex/odyssey.git cd odyssey mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release .. make

参考

https://github.com/yandex/odyssey

535_PGCon_2019_Borodin_Odyssey

PostgreSQL 许愿链接

您的愿望将传达给PG kernel hacker、数据库厂商等, 帮助提高数据库产品质量和功能, 说不定下一个PG版本就有您提出的功能点. 针对非常好的提议,奖励限量版PG文化衫、纪念品、贴纸、PG热门书籍等,奖品丰富,快来许愿。开不开森.

9.9元购买3个月阿里云RDS PostgreSQL实例

PostgreSQL 解决方案集合

德哥 / digoal's github - 公益是一辈子的事.

digoal's wechat

文章转载自digoal,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论