Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Яндекс.Директ: как мы деплоим наши Perl-web-приложения

Яндекс.Директ: как мы деплоим наши Perl-web-приложения

Elena Bolshakova

June 13, 2014
Tweet

More Decks by Elena Bolshakova

Other Decks in Programming

Transcript

  1. ßíäåêñ.Äèðåêò: êàê ìû äåïëîèì íàøè
    Perl-ïðèëîæåíèÿ
    Åëåíà Áîëüøàêîâà
    2014-06-13

    View full-size slide

  2. Section 1
    Êòî ìû

    View full-size slide

  3. Ýòî ßíäåêñ

    View full-size slide

  4. Ýòî ðåêëàìà

    View full-size slide

  5. Ýòî ðàçìåùåíèå ðåêëàìû â ßíäåêñå Äèðåêò

    View full-size slide

  6. Section 2
    Êàêèå ìû

    View full-size slide

  7. Öèôðû
    íåïðåðûâíàÿ ðàçðàáîòêà ñ 2003 ãîäà;
    300 KSLOC perl-êîäà;
    ∼1000 èìåíîâàííûõ åäèíèö ôóíêöèîíàëüíîñòè:
    ñòðàíèöû web-èíòåðôåéñà;
    ìåòîäû âíåøíåãî API;
    ìåòîäû âíóòðåííèõ API;
    êðîíîâûå ñêðèïòû;
    èåðàðõèÿ ïîëüçîâàòåëåé (>15 ðîëåé);
    30 ìëí. âíåøíèõ çàïðîñîâ ê perl-ïðèëîæåíèÿì / ñóòêè
    (ìíîãî çàïèñåé è òÿæåëûõ ÷òåíèé);
    mysql: ∼170 ìëðä. çàïèñåé
    îáùåíèå ñ äåñÿòêàìè ñìåæíûõ ñåðâèñîâ;
    ñåé÷àñ ∼40 ðàçðàáîò÷èêîâ, â ò.÷. ∼20 perl-ðàçðàáîò÷èêîâ;
    10000 êîììèòîâ / 7 ìåñÿöåâ, â ò.÷. 2500 trunk-êîììèòîâ;
    ïðîäàêøåí: perl-êîä íà ∼40 ñåðâåðàõ;
    ∼2 ðåëèçà â íåäåëþ.

    View full-size slide

  8. Òåõíîëîãèè
    ubuntu
    perl
    server-side javascript
    python, django
    mysql
    mongodb
    map-reduce (YT)
    memcached

    View full-size slide

  9. Òåõíîëîãèè-2
    plack
    apache
    nginx
    starman
    gearman
    ubic
    soap (SOAP::Lite)
    xmlrpc (XMLRPC::Lite)
    jsonrpc (JSON::RPC, JSON::RPC::Simple::Client,
    JSON::RPC2::Client)

    View full-size slide

  10. Ñðåäû
    ðàçðàáîò÷åñêèå, ÒÑ, ïðîäàêøåí:
    ðàçðàáîò÷åñêèå ñ óïðîùåííîé èíôðàñòðóêòóðîé;
    ÒÑ ñ ïîëíîöåííîé, êàê íà ïðîäàêøåíå;
    ðàçðàáîò÷åñêèå è òåñòîâûå ÁÄ: îáåçëè÷åííûé áåêàï
    ïðîäàêøåíà
    ðåãóëÿðíî òåñòèðóåòñÿ áåêàï è âîññòàíîâëåíèå;
    ðàçíîîáðàçíûå äàííûå äëÿ òåñòèðîâàíèÿ;
    äîñòóïû ðàçäåëåíû (ïðîäàêøåí îáíîâëÿþò òîëüêî
    àäìèíû).

    View full-size slide

  11. Section 3
    Ïîðà â ïðîäàêøåí

    View full-size slide

  12. Óïðàâëåíèå ñåðâåðàìè
    Ñîáñòâåííàÿ Rex-ïîäîáíàÿ óòèëèòà
    ïîâåðõ ssh;
    íà óïðàâëÿåìûõ ìàøèíàõ íèêàêèõ àãåíòîâ.

    View full-size slide

  13. Ðåëèçû
    ïåðâè÷íûé èñòî÷íèê èíôîðìàöèè î ðåëèçàõ òðåêåð:
    ÷òî è êàê âûêëàäûâàåì;
    êàêèå ïðîáëåìû íàéäåíû;
    ñòàòóñû (ïîäòâåðæäåíèÿ QA, çàêàç÷èêà, RM);
    êàæäûé ðåëèç òåñòèðóåòñÿ íà ÒÑ;
    ÷òî òåñòèðîâàòü:
    èçìåíåíèÿ îò ïðîøëîãî ðåëèçà (svn log);
    ðåãðåññèîííûå òåñòû;
    â êàæäîì commit-message ññûëêà íà òèêåò â òðåêåðå
    (ïðîâåðÿåòñÿ svn hook-îì).

    View full-size slide

  14. Êîä
    deb-ïàêåòû, apt
    Óäîáíî:
    ðàáîòàåò;
    óíèâåðñàëüíî;
    ìíîãî ãîòîâûõ èíñòðóìåíòîâ;
    çàâèñèìîñòè, â ò.÷. íåïåðëîâûå.
    Íåóäîáíî:
    óñòàíàâëèâàòü íå âåðõíþþ âåðñèþ íåïðîñòî;
    ïîëíîöåííî îòêàòèòü âñå êàê áûëî íåïðîñòî.

    View full-size slide

  15. Êîä, ìàëåíüêèå õèòðîñòè
    mainline releasable;
    ïàêåòèðóåòñÿ ëèáî òðàíê, ëèáî ðåëèçíûé áðàí÷ (òðàíê +
    ÷åððè-ïèê);
    ïî âåðñèè âñåãäà ïîíÿòíî, êàêàÿ òî÷êà â ðåïîçèòîðèè
    ïàêåòèðîâàëàñü;
    îòäåëüíûé êîíòðîëèðóåìûé deb-ðåïîçèòîðèé;
    æóðíàë: ÷òî âûëîæåíî â êàæäûé ìîìåíò íà ñåðâåðàõ,
    ïèñüìà îá îáíîâëåíèÿõ;
    çàâèñèìîñòè óêàçûâàòü ñ >=;
    ïîòåíöèàëüíî îïàñíûå/ñëîæíîîòêàòûâàåìûå îáíîâëåíèÿ
    îòäåëüíî îò ïðî÷èõ ðåëèçîâ;
    çàðàíåå ïðîâåðÿòü ïðèãîäíîñòü çàâèñèìîñòåé ê óñòàíîâêå.

    View full-size slide

  16. Ìèãðàöèè: èçìåíåíèå ñòðóêòóðû ÁÄ (àëüòåðû)
    Ôàéëû ìèãðàöèé â /deploy
    ïèøóòñÿ è êîììèòÿòñÿ âìåñòå ñ êîäîì;
    ôîðìàò ñòðîãèé, íî ÷åëîâåêî÷èòàåìûé:
    20140613_client_comments.migr
    {
    type => 'sql',
    db => 'main',
    when => 'before',
    time_estimate => "20 sec",
    sql => "alter table clients add column
    `comment` varchar(140) default ''",
    }
    ïðèìåíÿþòñÿ ïîëóàâòîìàòè÷åñêè íà ÒÑ, âðó÷íóþ íà
    ïðîäàêøåíå;

    View full-size slide

  17. Ìèãðàöèè: êîíâåðòàöèè äàííûõ
    20140614_normalize_geo.migr
    {
    type => 'script',
    when => 'after',
    time_estimate => "10 ÷àñîâ",
    comment => "åñëè óïàäåò -- ìîæíî çàïóñêàòü çàíîâî",
    script => "normalize_geo.pl",
    }

    View full-size slide

  18. Ìèãðàöèè: ïðî÷èå äåéñòâèÿ
    20131218_upgrade_nginx.migr
    {
    type => 'manual',
    when => 'any',
    time_estimate => "10 min",
    text => "Âûïîëíèòü íà ñåðâåðàõ ãðóïïû PERL:
    apt-get install nginx-common=1.4.4-5 nginx=1.4.4-5 \
    nginx-full=1.4.4-5
    è çàòåì
    nginx-upgrade
    ",
    }

    View full-size slide

  19. Ìèãðàöèè: æäåò ðåøåíèÿ
    àâòîìàòè÷åñêè ïðîâåðÿòü ïðèìåíåííîñòü;
    ïðîñòûå ñêðèïòû çàïóñêàòü áåç ó÷àñòèÿ ÷åëîâåêà.

    View full-size slide

  20. Ìèãðàöèè: ìàëåíüêèå õèòðîñòè
    ãëîáàëüíîãî ïîðÿäêà íåò;
    ÷åëîâåêîïîíÿòíûå èìåíà ñ ïðèìåðíîé äàòîé;
    îáÿçàòåëüíûå ðåâüþ è àïïðóâû;
    óíèâåðñàëüíûé ôîðìàò äëÿ âñåõ äåéñòâèé,
    ñîïðîâîæäàþùèõ îáíîâëåíèå êîäà;
    õåëïåð äëÿ ñîçäàíèÿ øàáëîíà ìèãðàöèè;
    ïàðñèíã: Safe::reval;
    ñòðîãàÿ âàëèäàöèÿ;
    ïðîâåðêà ñèíòàêñèñà sql: DBIx::MyParsePP;
    âðåìÿ ïðèìåíåíèÿ: äî/ïîñëå âûêëàäêè êîäà/êîãäà óãîäíî;
    òÿæåëûå ìèãðàöèè;
    òåêñòîâûå îïèñàíèÿ ìèãðàöèé ïèøóòñÿ âìåñòå ñ
    changelog-îì â ðåëèçíûé òèêåò;
    åñëè íàäî êîììåíòàðèè, êàê îòêàòûâàòü.

    View full-size slide

  21. Ìîíèòîðèíã ñõåìû ÁÄ
    Ôàéëû â /db_schema
    .schema.sql, .data.sql ñõåìû è ñëîâàðíûå äàííûå;
    .text îïèñàíèå òàáëèö;
    ñêðèïò äëÿ ñðàâíåíèÿ ÁÄ ñ ôàéëàìè;
    îò÷åòû î ðàñõîæäåíèè ïðîäàêøåí-áàçû è ñîõðàíåííûõ
    ñõåì.
    À åùå SchemaSpy: âèçóàëèçàöèÿ ñâÿçåé â ÁÄ.
    Æäåò ðåøåíèÿ: ïðîâåðÿòü àêòóàëüíîñòü ñîõðàíåííûõ ñõåì
    ñðàçó ïîñëå êîììèòà.

    View full-size slide

  22. Ðåãóëÿðíûå çàïóñêè ñêðèïòîâ
    Ôàéëû â /etc/cron.d
    Ãåíåðèðóþòñÿ ïðè ñáîðêå ïàêåòîâ èç pod + íåìíîãî
    ïîäãîòîâëåííûõ çàðàíåå

    View full-size slide

  23. Section 4
    Áîíóñ-òðåê

    View full-size slide

  24. Ïðîâåðêè, êîòîðûå äåëàþò æèçíü ñïîêîéíåå
    ñèíòàêñèñ è ïîäòâåðæäåííîñòü ìèãðàöèé;
    îòñóòñòâèå îòëàäî÷íîé ïå÷àòè â ñêðèïòàõ ìèãðàöèé;
    ñèíòàêñèñ êðîíòàáîâ (íàïðèìåð: ïðè îòñóòñòâèè ïåðåâîäà
    ñòðîêè â êîíöå ôàéëà cron èãíîðèðóåò ôàéë);
    ñîîòâåòñòâèå ñóùåñòâóþùèõ ñêðèïòîâ è çàïèñåé â
    êðîíòàáàõ;
    ïðàâèëüíûå ôàéëû â /debian: ãëîáàëüíûå ôàéëû +
    ôàéëû, îòíîñÿùèåñÿ ê ñóùåñòâóþùèì ïàêåòàì;
    êîìïèëÿöèÿ âñåãî perl-êîäà;
    êîìïèëÿöèÿ âñåõ TT-øàáëîíîâ;
    ñîîòâåòñòâèå èñïîëüçóåìûõ è ñóùåñòâóþùèõ øàáëîíîâ;
    íà âñåõ ñêðèïòàõ åñòü svn:executable + ïðàâèëüíûé shebang;

    View full-size slide

  25. Ïðîâåðêè, êîòîðûå äåëàþò æèçíü ñïîêîéíåå
    îòñóòñòâèå ñëåäîâ íåäîðàçðåøåííûõ êîíôëèêòîâ;
    mergeinfo òîëüêî íà êîðíå ïðîåêòà;
    íå÷åëîâåêî÷èòàåìûå ôàéëû èìåþò ïðàâèëüíûé mime-type;
    âñå èñõîäíèêè â utf8;
    ìåòêà NO_PRODUCTION.

    View full-size slide

  26. Ñïàñèáî!
    Âîïðîñû?
    Åëåíà Áîëüøàêîâà, [email protected]

    View full-size slide