Contenu connexe Similaire à Performance measurement and tuning Similaire à Performance measurement and tuning (20) Performance measurement and tuning2. About Us
Axel Jung
Software Developer
AOE media GmbH
Timo Schmidt
Software Developer
AOE media GmbH
3. 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
6. But I expect a lot of
visitors. Can you handle
them?
Yes, we can!
12. Install XDebug & KCachegrind
● Install xdebug
(eg. apt-get install php5-xdebug)
● Install kcachegrind
(eg. apt-get install kcachegrind)
17. Analyzing Cachegrinds
● High self / medium self and
many calls =>
High potential for optimization
● Early in call graph & not needed =>
High potential for optimization
18. Hands on
● There is an extension „slowstock“
in the VM.
● Open:
„http://typo3.t3dd2012/index.php?id=2“ and analyze it with kcachegrind.
22. 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)
23. 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)
25. 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.
26. 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;
}
27. 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);
}
28. 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);
}
29. Total Time Cost 5187627 ( ~ -50%)
Much better, but let's look on the call
graph... do we need all that stuff?
32. 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'], ...);
34. 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
99. 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: postfach@aoemedia.de
Web: http://www.aoemedia.de