身处互联网的SA(运维)们总感叹自己职业的苦逼,Why?我来告诉你:APP奔溃、网站打不开、网站502、搜索缓慢、应用卡顿通通找运维,运营、项目经理、老板等等围着运维,看其救火。有些运维甚至受到各种指责,例如:技术差、准备不充分、服务器优化的不行等等。面对千千万万的项目,运维为什么总在救火和受委屈,而研发却在不断制造BUG。
问题定位
一旦出现故障,通常先查日志,通过日志分析定位到某些服务器及项目,紧接着缩小范围至某个项目,最后SA与研发之间各种配合,最终找出问题并修复。
每次紧急救火之后,运维总会发问:为什么不能提前发现问题?是否有一个工具能让运维/开发事先发现问题并消灰掉,或者上线能够在故障出现之时快速定位到稳定。大家都应该认识到,通过常规方式来定位代码问题效率非常低,而且非常考验技术人员对业务熟悉程度以及个人技术能力。
解决方案
在日常工作中,常有人咨询我系统出现某种问题或者偶尔出现问题时怎么查找原因,除了给出解决方案以外,我总会告诉他:去试试APM吧,能够帮你快速发现问题,定位问题的原因。今天我要给SA们介绍一款国内纯自主开发的APM产品---透视宝。
透视宝功能
APM是应用性能管理(Application Performance Management)的缩写,通过对IT系统进行代码级的实时监测和分析,即时发现系统运行瓶颈,并进行告警和预警,帮助运维、开发迅速定位系统问题。透视宝包含APM(应用性能管理)、mobile、browser、host四项功能:
透视宝之安装
透视宝的安装比较简单,透视宝官方文档也非常清楚。
请直接看文档: http://portal.toushibao.com/app/create
透视宝之主机管理
安装完Smart Agent之后,登陆透视宝后台便能看到新增加的主机,如下图:
今天的主题不在“主机”,既然提到了,那么我简单的给大家展示透视宝下的主机基本监控。
服务器CPU、内存、进程、网卡、TCP监控项都有。如果这些基础监控能够满足你,那么完全可以放弃Zabbix等上手困难的开源监控产品了。看看监控效果:
透视宝之APM
透视宝APM目前支持主流的Java、PHP、Python、.Net四种语言的代码性能监测,PHP监测已经支持最新的PHP7正式版,我们主要以PHP为例感受一下APM的威力。
备注:起初准备拿ttlsa.com来体验,因为种种原因,最终换成了另外一个测试站点,请求量稍微少点,但是追踪PHP性能问题的方法还是一样的,一样能帮助我们找出代码性能问题。
点击应用,并选择你需要追踪的域名,通过请求、数据库、错误这三项目来找出PHP性能问题所在
APM之请求
首先看概览图,着重看缓慢、非常缓慢、错误的比率,如果比较高,那么要引起重视。
正常:2000毫秒
透视宝列出所有请求URL,以及URI对应的响应时间与请求数。
按照响应时间排序,点击响应时间较长的URL,右侧出现如下记录
点击记录进行追踪,可以看到整个请求耗时TOP5的方法,并可进行代码追踪、获取请求参数、SQL语句,最真实的还原当时环境。
- 概览图
- 追踪详情
这里非常重要,耗时(MS)越长的函数/方法说明性能越差. 由此,基本上已经定位到了性能问题代码,把相应的方法截图给研发吧。发现没?不懂代码的你也能抓出PHP性能代码。
- 请求参数
通过当前的请求参数最真实的还原现场
- SQL语句
一个缓慢响应请求部分由代码写法不恰当引起,还有一部分由效率低下的慢SQL引起。透视宝能够追踪到一个请求包含的所有SQL语句;由此,我们能快速的定位到SQL问题,并提交给研发/DBA优化。
APM之数据库
透视宝APM能够通过”请求”找出性能差的code、性能低下的慢SQL。透视宝能够通过”数据库”找出性能低下的慢SQL,并找出慢SQL对应的请求。”数据库”这块建议DBA经常浏览,并定期优化慢SQL。
透视宝提供了非常清晰易懂的SQL性能图表,让开发人员清晰的了解当前SQL使用情况,例如:SQL操作响应时间(TOPS)、吞吐量(含select、delete、insert、update)
透视宝会列出所有SQL操作列表,按照平均响应时间排序,选择需要解决的SQL记录,可定位对应请求耗时的接口/页面以及对应的慢SQL语句。
慢SQL追踪
APM之错误
除了透过请求与数据库来发现问题之外,我们也应该经常关注”错误”。
附录:透视宝插件
SendProxy、Discover和OSAgent插件是Smart Agent默认的基础插件,目前Smart Agent提供的插件如下表所示。

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor
