Performance measurement and tuning

99
High performance websites An introduction into xDebug profiling, Kcachegrind and JMeter

Transcript of Performance measurement and tuning

Page 1: Performance measurement and tuning

High performance websites An introduction into xDebug profiling, Kcachegrind and JMeter

Page 2: Performance measurement and tuning

About Us

Axel Jung Software Developer

AOE media GmbH

Timo Schmidt Software Developer

AOE media GmbH

Page 3: Performance measurement and tuning

Preparation

Install Virtualbox and import the t3dd2012 appliance (User & Password: t3dd2012)

You will find: • Apache with xdebug and apc • Jmeter • Kcachegrind • PHPStorm

There are two vhost: • typo3.t3dd2012 and playground.t3dd2012

Page 4: Performance measurement and tuning
Page 5: Performance measurement and tuning

Can you build a new

website for me?

Yes, we can!

Page 6: Performance measurement and tuning

But I expect a lot of

visitors. Can you handle them?

Yes, we can!

Page 7: Performance measurement and tuning

Really?

Yes, we can!

Page 8: Performance measurement and tuning

...after inventing the next, cutting edge, enterprise

architecture...

Page 9: Performance measurement and tuning

...and some* days of development...

Page 10: Performance measurement and tuning

The servers are not fast enough for your application ;)

Page 11: Performance measurement and tuning

INSTALL AND CONFIGURE xDebug

Page 12: Performance measurement and tuning

Install XDebug & KCachegrind

● Install xdebug (eg. apt-get install php5-xdebug) ● Install kcachegrind (eg. apt-get install kcachegrind)

Page 13: Performance measurement and tuning

● Configuration in (/etc/php5/conf.d/xdebug.ini on Ubuntu)

● xdebug.profiler_enable_trigger = 1 ● xdebug.profiler_output_dir = /..

Configure xDebug

Page 14: Performance measurement and tuning

● By request: ?XDEBUG_PROFILE ● All requests by htaccess: php_value xdebug.profiler_enable 1

Profiling

Page 15: Performance measurement and tuning

Open with KCachegrind

Page 16: Performance measurement and tuning

OPTIMIZE WITH IDE AND MIND KCachegrind

Page 17: Performance measurement and tuning

Analyzing Cachegrinds ● High self / medium self and many calls => High potential for optimization ● Early in call graph & not needed => High potential for optimization

Page 18: Performance measurement and tuning

Hands on

● There is an extension „slowstock“ in the VM. ● Open: „http://typo3.t3dd2012/index.php?id=2“ and analyze it with kcachegrind.

Page 19: Performance measurement and tuning
Page 20: Performance measurement and tuning

Total Time Cost 12769352

This code is very time consuming

Page 21: Performance measurement and tuning

SoapClient is instantiated everytime => move to constructor

Change 1 (SoapConversionRateProvider)

Page 22: Performance measurement and tuning

Before: /** * @param string $fromCurrency * @param string $toCurrency * @return float */ public function getConversionRate($fromCurrency, $toCurrency) { $converter = new SoapClient($this->wsdl); $in = new stdClass(); $in->FromCurrency = $fromCurrency; $in->ToCurrency = $toCurrency; $out = $converter->ConversionRate($in); $result = $out->ConversionRateResult; return $result; }

Change 1 (SoapConversionRateProvider)

Page 23: Performance measurement and tuning

After: /** @var SoapClient */ protected $converter; /** @return void */ public function __construct() { $this->converter = new SoapClient($this->wsdl); } /** * @param string $fromCurrency * @param string $toCurrency * @return float */ public function getConversionRate($fromCurrency, $toCurrency) { $in = new stdClass(); $in->FromCurrency = $fromCurrency; $in->ToCurrency = $toCurrency; $out = $this->converter->ConversionRate($in); $result = $out->ConversionRateResult; return $result; }

Change 1 (SoapConversionRateProvider)

Page 24: Performance measurement and tuning

Total Time Cost 10910560 ( ~ -15%)

11,99 % is still much time :(

Page 25: Performance measurement and tuning

Change 2 (SoapConversionRateProvider)

● Conversion rates can be cached in APC cache to reduce webservice calls. – Inject „ConversionRateCache“ into

SoapConversionRateProvider.

–Use the cache in the convert method.

Page 26: Performance measurement and tuning

Change 2 (SoapConversionRateProvider) Before: /** @var SoapClient */ protected $converter; /** @return void */ public function __construct() { $this->converter = new SoapClient($this->wsdl); } /** * @param string $fromCurrency * @param string $toCurrency * @return float */ public function getConversionRate($fromCurrency, $toCurrency) { $in = new stdClass(); $in->FromCurrency = $fromCurrency; $in->ToCurrency = $toCurrency; $out = $this->converter->ConversionRate($in); $result = $out->ConversionRateResult; return $result; }

Page 27: Performance measurement and tuning

Change 2 (SoapConversionRateProvider) After: /** @var Tx_Slowstock_System_Cache_ConversionRateCache */ protected $cache; ... /** @param Tx_Slowstock_System_Cache_ConversionRateCache $cache */ public function injectRateCache(Tx_Slowstock_System_Cache_ConversionRateCache $cache) { $this->cache = $cache; } … public function getConversionRate($fromCurrency, $toCurrency) { $cacheKey = $fromCurrency.'-'.$toCurrency; if(!$this->cache->has($cacheKey)) { $in = new stdClass(); $in->FromCurrency = $fromCurrency; $in->ToCurrency = $toCurrency; $out = $this->converter->ConversionRate($in); $result = $out->ConversionRateResult; $this->cache->set($cacheKey, $result); } return $this->cache->get($cacheKey); }

Page 28: Performance measurement and tuning

Change 2 (SoapConversionRateProvider) After: /** @var Tx_Slowstock_System_Cache_ConversionRateCache */ protected $cache; ... /** @param Tx_Slowstock_System_Cache_ConversionRateCache $cache */ public function injectRateCache(Tx_Slowstock_System_Cache_ConversionRateCache $cache) { $this->cache = $cache; } … public function getConversionRate($fromCurrency, $toCurrency) { $cacheKey = $fromCurrency.'-'.$toCurrency; if(!$this->cache->has($cacheKey)) { $in = new stdClass(); $in->FromCurrency = $fromCurrency; $in->ToCurrency = $toCurrency; $out = $this->converter->ConversionRate($in); $result = $out->ConversionRateResult; $this->cache->set($cacheKey, $result); } return $this->cache->get($cacheKey); }

Page 29: Performance measurement and tuning

Total Time Cost 5187627 ( ~ -50%)

Much better, but let's look on the call graph... do we need all that stuff?

Page 30: Performance measurement and tuning

The kcachegrind call graph

Page 31: Performance measurement and tuning

The kcachegrind call graph

Do we need any TCA in Eid? No

Page 32: Performance measurement and tuning

Change 3 – Remove unneeded code: (Resources/Private/Eid/rates.php):

Before: tslib_eidtools::connectDB(); tslib_eidtools::initTCA(); $TSFE = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], ...); After: tslib_eidtools::connectDB(); $TSFE = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], ...);

Page 33: Performance measurement and tuning

Total Time Cost 2877900 ( ~ -45%)

Page 34: Performance measurement and tuning

Summary

● From 12769352 => 2877900 (-77%) with three changes ● Additional Ideas:

● Reduce created fluid objects by implementing static fluid view helpers

(examples in fluid core)

● Cache reverse conversion rate (1/rate)

● Use APC Cache Backend for TYPO3 and Extbase caches

Page 35: Performance measurement and tuning

JMeter

http://jmeter.apache.org/

Page 36: Performance measurement and tuning

Why Jmeter?

Page 37: Performance measurement and tuning

BUILD A SIMPLE WEB TESTPLAN JMeter

Page 38: Performance measurement and tuning

JMeter Gui

Page 39: Performance measurement and tuning

Add Thread Group

Page 40: Performance measurement and tuning

Name Group

Page 41: Performance measurement and tuning

Add HTTP Defaults

Page 42: Performance measurement and tuning

Set Server

Page 43: Performance measurement and tuning

Add HTTP Sampler

Page 44: Performance measurement and tuning

Set Path

Page 45: Performance measurement and tuning

Add Listener

Page 46: Performance measurement and tuning

Start Tests

Page 47: Performance measurement and tuning

View Results

Page 48: Performance measurement and tuning

RECORD WITH PROXY JMeter

Page 49: Performance measurement and tuning

Add Recording Controller

Page 50: Performance measurement and tuning

Add Proxy Server

Page 51: Performance measurement and tuning

Exclude Assets

Page 52: Performance measurement and tuning

Start

Page 53: Performance measurement and tuning

Configure Browser

Page 54: Performance measurement and tuning

Browse

Page 55: Performance measurement and tuning

View results

Page 56: Performance measurement and tuning

ADVANCED JMeter

Page 57: Performance measurement and tuning

Add Asserts

Page 58: Performance measurement and tuning

Match Text

Page 59: Performance measurement and tuning

Constant Timer

Page 60: Performance measurement and tuning

Set the Base

Page 61: Performance measurement and tuning

Summary Report

Page 62: Performance measurement and tuning

Graph Report

Page 63: Performance measurement and tuning

Define Variables

Page 64: Performance measurement and tuning

Use Variables

Page 65: Performance measurement and tuning

CSV Files

Page 66: Performance measurement and tuning

CSV Settings

Page 67: Performance measurement and tuning

Use CSV Vars

Page 68: Performance measurement and tuning

Command Line

• /…/jmeter -n -t plan.jmx -l build/logs/testplan.jtl -j build/logs/testplan.log

Page 69: Performance measurement and tuning

Jenkins and JMeter

Page 70: Performance measurement and tuning

Detail Report

Page 71: Performance measurement and tuning

Use Properties

-p ${properties}

Page 72: Performance measurement and tuning

DISTRIBUTED TESTING

JMeter + Cloud

Page 73: Performance measurement and tuning

Start Server

Page 74: Performance measurement and tuning

jmeter.properties

remote_hosts=127.0.0.1

Page 75: Performance measurement and tuning

Run Slaves

Page 76: Performance measurement and tuning

AMAZON CLOUD http://aws.amazon.com/

Page 77: Performance measurement and tuning

Create User

Page 78: Performance measurement and tuning

EC2

Page 79: Performance measurement and tuning

Create Key

Page 80: Performance measurement and tuning

Name Key

Page 81: Performance measurement and tuning

Download Key

Page 82: Performance measurement and tuning

Create Security Groups

Page 83: Performance measurement and tuning

Launch

Page 84: Performance measurement and tuning

Select AMI ami-3586be41

Page 85: Performance measurement and tuning

Minimum Small

Page 86: Performance measurement and tuning

Configure Firewall

Page 87: Performance measurement and tuning

Wait 15 Min

Page 88: Performance measurement and tuning

Get Adress

Page 89: Performance measurement and tuning

Connect

Page 90: Performance measurement and tuning

Start Cloud Tool

Page 91: Performance measurement and tuning

Start Instances

Page 92: Performance measurement and tuning

Wait for Slaves

Page 93: Performance measurement and tuning

Slave Log

Page 94: Performance measurement and tuning
Page 95: Performance measurement and tuning

Close JMeter

Page 96: Performance measurement and tuning

All Slave will be terminated

Page 97: Performance measurement and tuning

Slave AMI

• ami-963e0ce2 • Autostart JMeter im Server Mode

Page 98: Performance measurement and tuning

Costs

Page 99: Performance measurement and tuning

Want to know more?

European HQ: AOE media GmbH Borsigstraße 3 65205 Wiesbaden Tel.: +49 (0)6122 70 70 7 - 0 Fax: +49 (0)6122 70 70 7 - 199 E-Mail: [email protected] Web: http://www.aoemedia.de