1H.com                         1H.com                                       Exploiting the Newer Perl        ...
             AGENDA                         <ul>                                                   <li>Building feature ri...
             $  $$  $$$  $$  $                                If you rate my survey, I'll hook you up with $20 cPCache $$$...
             Plug-ins creation                         <ul>                                                   <li>jQuery <...
             cPanel plug-ins with jQuery                         #!/usr/bin/perl -w        use strict;        use JQuery::...
             cPanel plug-ins with jQuery                                       sub start {        my $my = shift;        m...
             cPanel plug-ins with jQuery                         my $tab = JQuery::Tabs->new(id => 'myTab',        addToJQ...
             cPanel plug-ins with jQuery
             JavaScript::Packer                         $ wc -l uncompressed.js         1078 uncompressed.js        $ ls -...
             JavaScript::Packer                         #!/usr/bin/perl -w        use strict;        use JavaScript::Packe...
             Why JSON and why JSON::XS                         <ul>                                                   <li>...
             Example with JSON                         #!/usr/bin/perl -w        use strict;        use JSON::XS;        m...
             Why queuing is helpful                         <ul>                 <li>Performance </li>         <ul>       ...
             Introduce Queuing                         <ul>                                                   <li>Gearman ...
             Gearman Architecture                         <ul>                 <li>Server - handles the queues  </li>     ...
             Gearman client                         #!/usr/bin/perl -w        use strict;        use Gearman::Client;     ...
             Gearman worker                         #!/usr/bin/perl -w        use strict;        use Gearman::Worker;     ...
             Gearman setup                         # make && make install        # gearmand -d -u gearman -p 4730         ...
             RabbitMQ architecture                  RabbitMQ                                                              ...
             RabbitMQ architecture                             RabbitMQ                                                   ...
             <ul>                 RabbitMQ setup                </ul>                        # yum install erlang        #...
             <ul>                 RabbitMQ client                </ul>                        #!/usr/bin/perl -w        us...
             <ul>                 RabbitMQ server                </ul>                        #!/usr/bin/perl -w        us...
             <ul>                 Caching                </ul>                        <ul>                                ...
             <ul>                 Cache::Memcached                </ul>                            memcached              ...
             <ul>                 Cache::Redis                </ul>
             Conclusions                         <ul>                                         </ul>
             Questions                           ?  ?  ?  ?        ?  ?  ?  ?    ?  ?        ?  ? ?  ? ?  ?  ?        ?   ...
                    Thank you               Please visit us at Booth 23                         Marian Marinov - mm@1h.com...
             $  $$  $$$  $$  $                                If you rate my survey, I'll hook you up with $20 cPCache $$$...
Upcoming SlideShare
Loading in …5
×

Exploiting the newer perl to improve your plugins

1,212 views

Published on

  • Be the first to comment

Exploiting the newer perl to improve your plugins

  1. 1. 1H.com 1H.com Exploiting the Newer Perl to Improve Your Plugins Marian Marinov - mm@1h.com Co-founder & CEO of 1H Ltd.
  2. 2. AGENDA <ul> <li>Building feature rich plug-ins the easy way </li> <li>Queuing for the masses </li> <li>Cache me please </li> </ul>
  3. 3. $ $$ $$$ $$ $ If you rate my survey, I'll hook you up with $20 cPCache $$$. Go to this address to take the survey: http://go.cpanel.net/b27 and come up to the podium once you've completed it.
  4. 4. Plug-ins creation <ul> <li>jQuery </li> <li>JavaScript::Packer </li> <li>JSON::XS </li> </ul>
  5. 5. cPanel plug-ins with jQuery #!/usr/bin/perl -w use strict; use JQuery::Demo; use JQuery::CSS; use CGI; package main; my $tester = new JQuery::Demo; $tester->run; package JQuery::Demo; use JQuery::Tabs;
  6. 6. cPanel plug-ins with jQuery sub start { my $my = shift; my $q = new CGI; $my->{info}{TITLE} = &quot;Tabs&quot;; my $jquery = $my->{jquery}; my @tabs = (&quot;tab 1&quot;,&quot;tab 2&quot;,&quot;tab 3&quot;,&quot;tab 4&quot;); my @texts = (&quot;line 1&quot;,&quot;line 2&quot;,&quot;line 3&quot;,&quot;line4&quot;);
  7. 7. cPanel plug-ins with jQuery my $tab = JQuery::Tabs->new(id => 'myTab', addToJQuery => $jquery, tabs => @tabs, remote => 'true', remoteProgram => 'jquery_tabs_results.pl', rm => 'myMode', spinner => 1 ); my $html = $tab->HTML; $my->{info}{BODY} = qq[<h1>START OF TAB EXAMPLE</h1>$html</div>END OF EXAMPLE</h1>]; }
  8. 8. cPanel plug-ins with jQuery
  9. 9. JavaScript::Packer $ wc -l uncompressed.js 1078 uncompressed.js $ ls -l uncompressed.js -rw-r--r-- 1 hackman hackman 31609 Oct 8 00:43 uncompressed.js $ ./minify-js.pl $ ls -l compressed.js -rw-rw-r-- 1 hackman hackman 15847 Oct 8 00:43 compressed.js $ wc -l compressed.js 0 compressed.js
  10. 10. JavaScript::Packer #!/usr/bin/perl -w use strict; use JavaScript::Packer; my $packer = JavaScript::Packer->init(); open( UNCOMPRESSED, 'uncompressed.js' ); open( COMPRESSED, '>compressed.js' ); my $js = join( '', <UNCOMPRESSED> ); $packer->minify( $js, { compress => 'best' }); print COMPRESSED $js; close(UNCOMPRESSED); close(COMPRESSED);
  11. 11. Why JSON and why JSON::XS <ul> <li>We need to transfer data </li> <li>XML is EVIL </li> <li>The best format with the least overhead </li> <li>The XS version is obviously faster </li> </ul>
  12. 12. Example with JSON #!/usr/bin/perl -w use strict; use JSON::XS; my %res = ( 'a' => 'line1', 'b' => 'line2' ); my $json = JSON::XS->new->ascii->pretty->allow_nonref; print $json->encode(%res); $ ./json-ex.pl {&quot;a&quot;:&quot;line1&quot;,&quot;b&quot;:&quot;line2&quot;}
  13. 13. Why queuing is helpful <ul> <li>Performance </li> <ul> <li>No need to handle your own forks </li> <li>Queing slow commands </li> <li>The data is &quot;HOT&quot; </li> </ul> <li>Concurrency </li> <ul> <li>&quot;HOT&quot; connections </li> <li>No need to think about the position in a file </li> </ul> <li>Security </li> <ul> <li>You have to encode and check the data sent to the functions </li> </ul> </ul>
  14. 14. Introduce Queuing <ul> <li>Gearman - http://gearman.org </li> <li>RabbitMQ - http://www.rabbitmq.com </li> </ul>
  15. 15. Gearman Architecture <ul> <li>Server - handles the queues </li> <li>Client - adds requests to the queue </li> <li>Worker - handles requests from the queue </li> </ul> Worker Client gearmand Web App Daemon
  16. 16. Gearman client #!/usr/bin/perl -w use strict; use Gearman::Client; my $client = Gearman::Client->new; $client->job_servers('127.0.0.1:4730'); $str = &quot;my client has called&quot;; eval { local $SIG{ALRM} = sub { die 'timeout'; }; alarm(3); $client->dispatch_background('log_me', $str); alarm(0); };
  17. 17. Gearman worker #!/usr/bin/perl -w use strict; use Gearman::Worker; use POSIX qw(strftime); $logfile = '/home/hackman/test.log'; open LOG, '>>', $logfile; select((select(LOG), $| = 1)[0]); my $logger = sub { ... }; my $w = Gearman::Worker->new; $w->job_servers('127.0.0.1:4730'); $w->register_function( log_me => $logger ); $w->work while 1;
  18. 18. Gearman setup # make && make install # gearmand -d -u gearman -p 4730 # gearman_status.pl function name queue exec worker log_me 1 1 1 check_oneh 0 0 1 gather_child 154 72 72
  19. 19. RabbitMQ architecture RabbitMQ Queue Exchange Server Server Queue Server
  20. 20. RabbitMQ architecture RabbitMQ AMQP XMPP STOMP HTTP AMQP XMPP STOMP HTTP
  21. 21. <ul> RabbitMQ setup </ul> # yum install erlang # rpm -Uvh rabbitmq-server-2.6.1-1.noarch.rpm # rabbitmq-server -detached # rabbitmqctl status Status of node rabbit@gamelon ... [{pid,6829}, {running_applications, [{rabbit,&quot;RabbitMQ&quot;,&quot;2.6.1&quot;}, ....
  22. 22. <ul> RabbitMQ client </ul> #!/usr/bin/perl -w use strict; use Net::RabbitMQ; my $mq = Net::RabbitMQ->new(); $mq->connect(&quot;localhost&quot;, { user => &quot;guest&quot;, password => &quot;guest&quot; }); $mq->channel_open(1); $mq->publish(1, &quot;testqueue&quot;, &quot;Hi there!&quot;); $mq->disconnect();
  23. 23. <ul> RabbitMQ server </ul> #!/usr/bin/perl -w use strict; use Data::Dumper ; use Net::RabbitMQ; my $mq = Net::RabbitMQ->new(); $mq->connect(&quot;localhost&quot;,{user=>&quot;guest&quot;,password=>&quot;guest&quot;}); $mq->channel_open(1); $mq->exchange_declare(1, 'my_x',{auto_delete => 0}); $mq->queue_declare(1, 'testqueue',{auto_delete => 0}); $mq->queue_bind(1, 'testqueue', 'my_x', 'foo'); while(1){ my $hashref = $mq->get(1, 'testqueue'); print Dumper($hashref) if (defined($hashref)); }
  24. 24. <ul> Caching </ul> <ul> <li>Why cache ? </li> <li>Cache::memcached </li> <li>Cache::Redis - written especially for this talk :) </li> </ul>
  25. 25. <ul> Cache::Memcached </ul> memcached CGI CGI CGI CGI CGI
  26. 26. <ul> Cache::Redis </ul>
  27. 27. Conclusions <ul> </ul>
  28. 28. Questions ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
  29. 29. Thank you Please visit us at Booth 23 Marian Marinov - mm@1h.com Co-founder & CIO at 1H Ltd. 1H.com 1H.com
  30. 30. $ $$ $$$ $$ $ If you rate my survey, I'll hook you up with $20 cPCache $$$. Go to this address to take the survey: http://go.cpanel.net/b27 and come up to the podium once you've completed it.

×