2014-10-08 5 views
1

파이썬에서 DB 연결 풀 (예 : psycopg2.pool 및 mysql.connector.pooling)의 유스 케이스를 이해하고 있는지 잘 모르겠습니다. 필자는 병렬 처리가 GIL 때문에 다중 스레드 접근 방식이 아닌 다중 프로세스 방식을 사용하여 파이썬에서 일반적으로 달성되는 것으로 보입니다. 다중 프로세스의 경우 이러한 풀이 각 프로세스가 자체 풀을 초기화 할 것이므로별로 유용하지 않습니다. 한 번에 하나의 스레드 만 실행합니다. 이 올바른지? 다중 프로세스를 사용할 때 DB 연결 풀을 공유하기위한 전략이 있습니까? 그렇지 않다면 멀티 스레드 파이썬 응용 프로그램에 한정된 풀링의 유용성이나 그렇지 않은 시나리오가 있습니까?파이썬에서 DB 연결 풀 이해하기

답변

3

키스,

당신은 올바른 길을 가고 있습니다. S.O 포스트 "Accessing a MySQL connection pool from Python multiprocessing"에서 언급 한 바와 같이 :

Making a seperate pool for each process is redundant and opens up way 
too many connections. 

체크 아웃 다른 S.O 포스트는 "What is the best solution for database connection pooling in python?"는 파이썬에서 샘플 풀링 솔루션이 포함되어 있습니다. 이 게시물도의 한계를 설명 DB 풀링 응용 프로그램이 멀티는 스레드가 될 것 인 경우 : 인 측면에서 언급 한 바와 같이, 파이썬에서 DB 풀링을 구현

Making your own connection pool is a BAD idea if your app ever decides to start using 
multi-threading. Making a connection pool for a multi-threaded application is much 
more complicated than one for a single-threaded application. You can use something 
like PySQLPool in that case. 

"Application vs Database Resident Connection Pool,"데이터베이스가 지원하는 경우, 최선의 구현에는 다음이 포함됩니다.

Let connection pool be maintained and managed by database itself 
(example: Oracle's DRCP) and calling modules just ask connections from the connection 
broker described by Oracle DRCP. 

질문이 있으시면 알려주세요.

+0

설명해 주셔서 감사합니다. – Keith