php CodeIgniter 中 pconnect 选项的优缺点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1830830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:58:46  来源:igfitidea点击:

Advantages / Disadvantages of pconnect option in CodeIgniter

phpdatabaseperformancecodeigniter

提问by Clayton

One of the parameters in the CodeIgniter database config is the following

CodeIgniter 数据库配置中的参数之一如下

['pconnect'] TRUE/FALSE - Whether to use a persistent connection

What do you recommend I set this to?
Is there a significant performance hit if I set it to FALSE?
What potential problems might arise from setting it to TRUE?

您建议我将其设置为什么?
如果我将其设置为 FALSE,是否会对性能造成重大影响?
将其设置为 TRUE 可能会出现哪些潜在问题?

回答by MarkR

Just look up general best practices for persistent connections. My suggestions.

只需查找持久连接的一般最佳实践。我的建议。

  • By default, DO NOT
  • If you have:
    • Dedicated web server and database hardware in production
    • and have tuned the web server and database correctly
    • and have an accurate production-like test environment
    • And still think your performance problems are caused by database connection time,
  • 默认情况下,不要
  • 如果你有:
    • 生产中的专用 Web 服务器和数据库硬件
    • 并正确调整了网络服务器和数据库
    • 并拥有准确的类似生产的测试环境
    • 并且仍然认为你的性能问题是数据库连接时间造成的,

CONSIDER turning it on

考虑打开它

Persistent connections can cause

持久连接可能导致

  • Bugs because some connection state persisted unintentionally (this is a biggie!)
  • Database connection limits to be exceeded
  • Database performance to drop because of lots of ram used by the many (mostly idle) connections
  • Bugs because connections have gone "stale" and the app didn't notice
  • 错误,因为某些连接状态无意中持续存在(这是一个大问题!)
  • 超出数据库连接限制
  • 由于许多(主要是空闲)连接使用大量内存,数据库性能下降
  • 错误,因为连接已经“过时”并且应用程序没有注意到

But CAN

但是可以

  • Reduce latency on initial connection
  • 减少初始连接的延迟

If you think that connection latency is causing a problem, consider turning it on in your performance test system and measuringthe impact.

如果您认为连接延迟导致问题,请考虑在您的性能测试系统中打开它并测量影响。