Your SlideShare is downloading. ×
0
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Tt subtemplates-caching
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Tt subtemplates-caching

586

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
586
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Óñêîðåíèå îáðàáîòêè øàáëîíîâ Template-Toolkit Èëè êýøèðîâàíèå ïîäøàáëîíîâ â TT Âàëåðèé Ñòóäåííèêîâ, despair@reg.ru Èþíü 2010 YAPC 2010
  • 2. Òÿæ¼ëûé ñàéò...
  • 3. Òîðìîçèò... Çàïðîñû îáðàáàòûâàþòñÿ ìåäëåííî... Document Length: 121170 bytes Concurrency Level: 1 ... Requests per second: 6.55 [#/sec] (mean) Time per request: 152.677 [ms] (mean)
  • 4. Ðàçáèðàåìñÿ â ïðè÷èíàõ... [debug] Rendering template "index.html" [info] Request took 0.155370s (6.436/s) .--------------------------------------+-----------. | Action | Time | +--------------------------------------+-----------+ | -> /_DISPATCH | 0.138753s | | -> /_BEGIN | 0.005263s | | /begin | 0.004580s | | -> /_AUTO | 0.000968s | | /auto | 0.000270s | | -> /_ACTION | 0.000883s | | /index | 0.000363s | | -> /_END | 0.129827s | | /end | 0.129265s | | -> FrontOffice::View::TT->process | 0.128254s | '--------------------------------------+-----------'
  • 5. Êàê äåòàëèçîâàòü ïî ïîäøàáëîíàì? Íàì ïîìîæåò ñòàòüÿ ¾Proling in Template Toolkit via overriding¿ by Randal L. Schwartz package My::Template::Context; } use base qw(Template::Context); } $totals{$template}[5] ++; # count of calls my @stack; my %totals; unless (@stack) { ## top level again, time to display results sub process { print STDERR -- $template at . localtime, :n my $self = shift; printf STDERR %3s %3s %6s %6s %6s %6s %sn, qw(cnt clk user sys cuser csys template); my $template = $_[0]; for my $template (sort keys %totals) { if (UNIVERSAL::isa($template, Template::Document)) { my @values = @{$totals{$template}}; $template = $template-name || $template; printf STDERR %3d %3d %6.2f %6.2f %6.2f %6.2f } $values[5], @values[0..4], $template; } push @stack, [time, times]; print STDERR -- endn; %totals = (); # clear out results my @return = wantarray ? } $self-SUPER::process(@_) : scalar $self-SUPER::process(@_); # return value from process: wantarray ? @return : $return[0]; my @delta_times = @{pop @stack}; } @delta_times = map { $_ - shift @delta_times } time, times; for (0..$#delta_times) { $Template::Config::CONTEXT = __PACKAGE__; $totals{$template}[$_] += $delta_times[$_]; for my $parent (@stack) { 1; $parent-[$_] += $delta_times[$_] if @stack; # parent adjust
  • 6. Ïðîôàéëèíã ïîäøàáëîíîâ -- index.html at Thu Jun 10 18:20:56 2010: cnt clk user sys cuser csys template 1 0.0056 0.0000 0 0 0 common/footer_common.inc 1 0.0006 0.0000 0 0 0 common/header_topline.inc 1 0.0006 0.0000 0 0 0 footer.inc 1 0.0004 0.0000 0 0 0 footer_screen.inc 1 0.0010 0.0000 0 0 0 header.inc 1 0.0010 0.0000 0 0 0 header_screen.inc 1 0.0187 0.0200 0 0 0 header_screen_body_cached.inc 1 0.0005 0.0000 0 0 0 header_screen_head_cached.inc 1 0.0015 0.0000 0 0 0 index.html 1 0.0036 0.0000 0 0 0 index_body.inc 1 0.0145 0.0200 0 0 0 index_promo_bar.inc 1 0.0775 0.0800 0 0 0 print/zones.inc 1 0.0004 0.0000 0 0 0 tabs.inc
  • 7. Ìîäóëü äëÿ êýøèðîâàíèÿ use Template : : C o n t e x t : : C a c h e a b l e ; Template : : C o n t e x t : : C a c h e a b l e : : c o n f i g u r e _ c a c h i n g ( SRS : : Cache : : Memcached : : get , SRS : : Cache : : Memcached : : put , ); $Template : : C o n t e x t : : C a c h e a b l e : : DEBUG = 1 ;
  • 8. Êàê ýòî âûãëÿäèò â øàáëîíàõ index.html: [% PROCESS index_reg_bar.inc lang = lang pricegroup = pricegroup __cache_time = -1 %]
  • 9. Êàê ýòî âûãëÿäèò â øàáëîíàõ header_screen.inc: [%- PROCESS header_screen_body_cached.inc ... __nocache_banner_no = banner_no __nocache_lang = lang __nocache_wide_flag = wide_flag __nocache_path_query = path_query __nocache_user_id = user_id __nocache_user_balance = user_balance ... __nocache_req_method = c.req.method __cache_time = user_messages.size() ? 0 : -1 -%]
  • 10. Âðóáàåì êýøèðîâàíèå... -- index.html at Thu Jun 10 18:52:04 2010: cnt clk user sys cuser csys template 1 0.0002 0 0 0 0 footer.inc CACHED 1 0.0010 0 0 0 0 header.inc 1 0.0005 0 0 0 0 header_screen.inc CACHED 1 0.0015 0 0 0 0 index.html 1 0.0002 0 0 0 0 index_body.inc CACHED 1 0.0003 0 0 0 0 index_promo_bar.inc CACHED 1 0.0004 0 0 0 0 print/zones.inc CACHED -- end
  • 11. Âðóáàåì êýøèðîâàíèå... [debug] Rendering template index.html [info] Request took 0.029016s (34.464/s) .-------------------------------------+-----------. | Action | Time | +-------------------------------------+-----------+ | - /_DISPATCH | 0.014121s | | - /_BEGIN | 0.002807s | | /begin | 0.002152s | | - /_AUTO | 0.000860s | | /auto | 0.000276s | | - /_ACTION | 0.000884s | | /index | 0.000370s | | - /_END | 0.007854s | | /end | 0.007279s | | - FrontOffice::View::TT-process| 0.006267s | '-------------------------------------+-----------'
  • 12. Ðåçóëüòàò... Server Hostname: www1.reg.ru Server Port: 80 Document Path: / Document Length: 121176 bytes Concurrency Level: 1 Time taken for tests: 9.524 seconds Total transferred: 36445800 bytes HTML transferred: 36352800 bytes Requests per second: 31.50 [#/sec] (mean) Time per request: 31.746 [ms] (mean) Transfer rate: 3737.15 [Kbytes/sec] received
  • 13. Ðåçóëüòàò... Óìåíüøèëè îáùåå âðåìÿ îáðàáîòêè çàïðîñà â 4.9 ðàçà; Óñêîðèëè îáðàáîòêó øàáëîíà â 20 ðàç;
  • 14. Ñïàñèáî! Ìîäóëü Template::Context::Cacheable ëåæèò òóò https://svn.reg.ru/oss/Template-Context-Cacheable/

×