- PostgreSQL 9.0 High Performance
- Gregory Smith
- 798字
- 2021-04-13 16:58:44
Work on improving database performance has its own terminology, just like any other field. Here are some terms or phrases that will be used throughout the book:
- Bottleneck or limiting factor: Both of these terms will be used to refer to the current limitation that is keeping the performance from getting better.
- Benchmarking: Running a test to determine how fast a particular operation can run. This is often done to figure out where the bottleneck of a program or system is.
- Profiling: Monitoring what parts of a program are using the most resources when running a difficult operation such as a benchmark. This is typically to help prove where the bottleneck is, and whether it's been removed as expected after a change. Profiling a database application usually starts with monitoring tools such as
vmstat
andiostat
. Popular profiling tools at the code level includegprof
,oprofile
, anddtrace
.
One of the interesting principles of performance tuning work is that, in general, you cannot figure out what the next bottleneck an application will run into is until you remove the current one. When presented with a system that's not as fast as someone would expect it to be, you'll often see people guessing what the current bottleneck is, or what the next one will be. That's generally a waste of time. You're always better off measuring performance, profiling the parts of the system that are slow, and using that to guess at causes and guide changes.
Let's say what you've looked at suggests that you should significantly increase shared_buffers
, the primary tunable for memory used to cache database reads and writes. This normally has some positive impact, but there are potential negative things you could encounter instead. The information needed to figure out which category a new application will fall into, whether this change will increase or decrease performance, cannot be predicted from watching the server running with the smaller setting. This falls into the category of chaos theory: even a tiny change in the starting conditions can end up rippling out to a very different end condition, as the server makes millions of decisions and they can be impacted to a small degree by that change. Similarly, if shared_buffers
is set too small, there are several other parameters that won't work as expected at all, such as those governing database checkpoints.
Since you can't predict what's going to happen most of the time, the mindset you need to adopt is one of heavy monitoring and change control. Monitor as much as possible—from application to database server to hardware. Introduce a small targeted change. Try to quantify what's different and be aware that some changes you have rejected as not positive won't always stay that way forever. Move the bottleneck to somewhere else, and you may discover that some parameter that didn't matter before is now suddenly the next limiting factor.
There's a popular expression on the mailing list devoted to PostgreSQL performance when people speculate about root causes without doing profiling to prove their theories: "less talk, more gprof
". While gprof
may not be the tool of choice for every performance issue, given it's more of a code profiling tool than a general monitoring one, the idea that you measure as much as possible before speculating as to the root causes is always a sound one. You should also measure again to validate your change did what you expected too.
Another principle that you'll find a recurring theme of this book is that you must be systematic about investigating performance issues. Do not assume your server is fast because you bought it from a reputable vendor; benchmark the individual components yourself. Don't start your database performance testing with application level tests; run synthetic database performance tests that you can compare against other people's first. That way, when you run into the inevitable application slowdown, you'll already know your hardware is operating as expected and that the database itself is running well. Once your system goes into production, some of the basic things you might need to do in order to find a performance problem, such as testing hardware speed, become impossible to take the system down.
You'll be in much better shape if every server you deploy is tested with a common methodology, which is exactly what later chapters here lead you through. Just because you're not a "hardware guy", it doesn't mean you should skip over the parts here that cover things like testing your disk performance. You need to perform work like that as often as possible when exposed to new systems—that's the only way to get a basic feel of whether something is operated within the standard range of behavior or if instead there's something wrong.
- 常用工具軟件案例教程
- 自己動手寫分布式搜索引擎
- 商用級AIGC繪畫創作與技巧(Midjourney+Stable Diffusion)
- AutoCAD 2017實用教程
- Swing Extreme Testing
- 3ds Max/VRay室內設計材質、燈光與建模速查超級手冊
- Spring Security 3
- iPhone JavaScript Cookbook
- 零基礎學數碼攝影后期
- Adobe創意大學Illustrator CS5 產品專家認證標準教材
- Java EE 6 with GlassFish 3 Application Server
- AutoCAD 2016入門與提高(超值版)
- Building Websites with VB.NET and DotNetNuke 4
- 剪映:從零開始精通短視頻剪輯(電腦版)
- Python 3 Web Development Beginner's Guide