Symfony2 + Doctrine
PostgreSQL
Symfony2 ve Doctrine ile PostgreSQL'i
kullanarak Performanslı Mimari oluşturma
1
çok sevdiğimiz diller
2
çok sevdiğimiz veribanları
3
çok sevdiğimiz ortamlar
4
yapan kraldır
5@okulbilisim
Ajanda
● Performans nedir?
● Performans analizi nasıl yapılır?
● Nginx ve FPM performans
● Symfony2 performans
● Doctrine performans
● Web Sayfasındaki performans
● Organik DDoS (Normal insan saldırısı)
6
facebook gibi hızlı geliyor
Performans?
7
her şeyi cachelemek, arkada yapıp getirmek iyidir
8
keşler
LB cache
Nginx FastCGI
app/cache and APC
Response caching & HTTP-CACHE
Doctrine2 Query & Result Caching
CDN
9
http://analytics.blogspot.com.tr/2012/04/global-site-speed-overview-how-fast-are.html
10
load test
Performans analizi nasıl
yapılır?
11
https://twitter.com/yuxel/status/279319192757493760
12
@GoyGoyTR
Load Test
http://jmeter.apache.org/
13
Araçlar
● htop
● siege
● hping3
● dstat
● wacth -n .5 ‘netstat -ant|grep ESTAB|wc -l’
● iostat
● çok bilgi
14
apache?
nginx + fpm
15
nginx + fpm
16
http://highscalability.com/blog/2014/4/30/10-tips-for-optimizing-nginx-and-php-fpm-for-high-traffic-si.html
http://lukasz.cepowski.com/devlog/43,high-performance-web-server-with-nginx-and-php-fpm
http://blog.martinfjordvald.com/2010/09/12000-requests-per-second-with-nginx-php-and-memcached/
1. SSD
2. TCP -> UNIX domain sockets.
3. worker_processes
4. worker_connections.
5. upstream
6. access_log off;
7. GZip.
8. fast_cgi_cache
9. client timeouts.
10. output buffers.
11. /etc/sysctl.conf
gc_disable
17
https://github.com/composer/composer/commit/ac676f47f7bbc619678a29deae097b6b0710b799
http://blog.ircmaxell.com/2014/12/what-about-garbage.html
Symfony2 Performans
18
19
Symfony zaten hızlı
Daha hızlı olması için yapabileceğiniz çok az şey var.
Byte Code Cache
Apc
Xcache
ionCube
Zend Opcache
20
Composer Class Map
composer dump-autoload --optimize
21
Dump Router
php app/console --env=prod router:dump...RewriteCond %{REQUEST_URI} ^/city$RewriteRule .* $0/ [QSA,L,R=301]RewriteCond %{REQUEST_URI} ^/city/$RewriteRule .* app.php [QSA,L,E=_ROUTING_route:city,E=_ROUTING_default__controller:TestBundle\\Controller\\CityController\:\:indexAction]...
22
Doctrine
23
Doctrine
The Doctrine Project is the home to several
PHP libraries primarily focused on database
storage and object mapping. The core projects
are a Object Relational Mapper (ORM) and
the Database Abstraction Layer (DBAL) it is
built upon.http://www.doctrine-project.org/
24
doctrine:orm:
metadata_cache_driver: memcachequery_cache_driver: memcacheresult_cache_driver: memcache
25
Memcache
APC
Redis
Xcache
File
Custom Cache Service
26
Metadata Cache
Her istek sırasında Annotation, YAML, XML gibi
farklı bir çok yerden class metadata
oluşturulmasının önüne geçer
27
Query Cache
DQL sorgusunun SQL karşılığının bir değişim
olmadığı sürece tekrar tekrar
oluşturulmasından kaynaklı performans kaybını
gidermek için
28
Result Cache
Sadece ihtiyaç halinde
$query = $em->createQuery('...');$query->useResultCache(true);
// setResultCacheLifetime(3600);// setResultCacheId('my_custom_id');// useResultCache(true, 3600, 'my_custom_id');
29
30
Cache Slam!
Fetch Modes
31
Lazy vs Extra LazyDoctrine 2.0 Doctrine 2.1
32
getSinlgeScalarResult
$ref = $em->createQuery( "SELECT PARTIAL s.title " . "FROM BlogBundle:Post s " . "WHERE s.id = ?1" )->setParameter(1, $id)->getSingleScalerResult()
33
getPartialReference
$ref = $em->createQuery( "SELECT PARTIAL s.{keywords,title} " . "FROM BlogBundle:Post s " . "WHERE s.id = ?1" )->setParameter(1, $id)->getResult();
$ref = $em->getPartialReference("BlogBundle:Post", $id)
34