duancai7002 2018-09-16 11:11
浏览 153
已采纳

建立与Azure PostgreSQL的连接的PDO非常慢

I have PHP application running as a Docker container based on Alpine Linux inside Kubernetes. Everything went well until I tried removing container with test database and replacing it with Azure PostgreSQL. This led to significant latency increase from under 250ms to above 1500ms.

According to profiler most time is spent in PDO constructor which is establishing connection to database. The SQL queries themselves, after connection was established, then run in about 20ms.

  • I tried using IP instead of address and it was still slow.
  • I tried connecting from container using psql and it was slow (see full command below)
  • I tried DNS resolution using bind-tools and it was fast.
  • Database runs in same region as Kubernetes nodes, tried even same resource group, different network settings and nothing helped.
  • I tried requiring/disabling SSL mode on both client and server
  • I tried repeatedly running 'select 1' inside an already established connection and it was fast (average 1.2ms, median 0.9ms) (see full query below)

What can cause such a latency? How can I further debug/investigate this issue?


psql command used to try connection:

psql "sslmode=disable host=host dbname=postgres user=user@host.postgres.database.azure.com password=password" -c "select 1"

Query speed

\timing 
SELECT;
\watch 1
  • 写回答

1条回答 默认 最新

  • doubingling4706 2018-12-18 13:21
    关注

    As far as I can tell it is caused by Azure specific authentication on top of PostgreSQL. Unfortunately Azure support was not able to help from their side.

    Using connection pool (PgBouncer) solves this problem. It is another piece of infrastructure we have to maintain (docker file, config/secret management, etc.), which we hoped to outsource to cloud provider.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题