Slide 1

Slide 1 text

Perl in Mercari 2018 @kazeburo
 YAPC::Okinawa 2018 ONNASON

Slide 2

Slide 2 text

େ੾ͳ͓஌Βͤ

Slide 3

Slide 3 text

memcached UDPϦϑϨΫγϣϯDDoS • Πϯλʔωοτʹެ։͞Ε͍ͯΔmemcached 11211/UDPΛར༻ͯ͠UDP ϦϑϨ Ϋγϣϯ͕ߦ͑Δ • github.com ʹ1.3TbpsͷDDoS߈ܸ͕ൃੜ (2/28) • ͘͞ΒVPS͸11211/UDPΛϑΟϧλϦϯά • [ॏཁ] memcachedΛάϩʔόϧʹެ։͠ͳ͍ • UDPΛແޮԽ͢Δɻmemcached -U 0Ͱىಈ
 memcached-1.5.6Ͱ͸σϑΥϧτແޮʹͳΓ·ͨ͠

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Me • ௕໺խ޿ • PAUSE:KAZEBURO • גࣜձࣾϝϧΧϦ
 ϓϦϯγύϧΤϯδχΞ
 Site Reliability Engineering (SRE) νʔϜ • BASE, Inc ٕज़ΞυόΠβʔ

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

ϝϧΧϦ • ࠃ಺࠷େڃͷϑϦϚΞϓϦ • 3෼Ͱ؆୯ʹग़඼ 1) ࣸਅΛࡱΔ 2) ঎඼৘ใΛهೖ 3) ग़඼ϘλϯΛԡ͢ • ҆৺҆શͳܾࡁɾऔҾ • ΤεΫϩʔ(͓ۚͷ΍ΓͱΓ͸౰͕ࣾؒʹհࡏ) • ಗ໊഑ૹ

Slide 8

Slide 8 text

KPI μ΢ϯϩʔυ਺ GMV(૯औҾֹ) 1ԯDLҎ্(JP+US+UK) ݄ؒ100ԯԁҎ্ ग़඼਺ 1೔100ສ඼Ҏ্

Slide 9

Slide 9 text

ϝϧΧϦΛࢧ͑Δ αʔόαΠυͷ ϓϩάϥϛϯάݴޠ

Slide 10

Slide 10 text

PHP 7

Slide 11

Slide 11 text

Golang https://github.com/golang-samples/gopher-vector

Slide 12

Slide 12 text

ϝϧΧϦΛࢧ͑Δϓϩάϥϛϯάݴޠ • ϝϧΧϦͷAPI͸΄΅શͯPHPʹΑΓ࣮૷ • ϚΠΫϩαʔϏε/ϛυϧ΢ΣΞͰ͸ Golang ͕த৺ • AI/MLͷ෼໺Ͱ͸Python΋࢖ΘΕΔ

Slide 13

Slide 13 text

1FSM͸ϝΠϯϦʔϜͳݴޠͰ͸ͳ͍

Slide 14

Slide 14 text

͕͔ͩ͠͠ খ͞ͳ Perl εΫϦϓτ͕αʔϏεͷ҆ఆՔಇΛࢧ͑ ཪํͱͯ͠େن໛ͳτϥϑΟοΫΛॲཧ͍ͯ͠Δɻ

Slide 15

Slide 15 text

slacklog

Slide 16

Slide 16 text

slacklog = cronlog + Slack notification

Slide 17

Slide 17 text

cronlog • cronlog ͸kazuho͞Μ࡞੒ͷPerlεΫϦϓτɻҾ਺ͱͯ͠༩͑ΒΕͨίϚϯ υΛ࣮ߦ͠ɺͦͷऴྃίʔυ͕ඇθϩͷ৔߹ͷΈɺίϚϯυͷग़ྗ (stdout, stderr)Λඪ४ग़ྗʹૹΔ • cronͰར༻͢Δ͜ͱͰΤϥʔ࣌ͷΈMAILTOʹϝʔϧૹ৴ • `5 * * * * cronlog -- ping -n 5 my-server 2>&1` • ʮ؂ࢹͱ͸ܧଓతͳςετʯͱ͍͏ݴ༿ΛੜΈग़ͨ͠

Slide 18

Slide 18 text

slacklog • ίϚϯυͷऴྃίʔυ͕ඇθϩ࣌ʹඪ४ग़ྗ΁ͷૹ৴ʹՃ͑ɺslack΁ͷ௨஌Λߦ͏ • @channel Λ௥Ճ͢Δ͔ࢦఆՄೳ • ىಈͱऴྃ࣌ʹSlack΁ͷ௨஌ɺsyslog΁΋ه࿥ • hostname,pid ͷ෇Ճ • slack΁ͷ௨஌͸ slackboard Λར༻ • ϝϧΧϦͷ΄΅શͯͷcronͰར༻͍ͯ͠Δ

Slide 19

Slide 19 text

slacklog use slackboard App Batch MySQL App Batch MySQL App Batch MySQL JP US UK slacklog slacklog slacklog slacklog slacklog slacklog slacklog slacklog slacklog slackborad slackborad slackborad JP US EU HTTP Load Balancer MySQL slacklog slacklog slacklog SlackͷAPI keyͷҰݩ؅ཧ Buffering/Queueing Slack https://github.com/cubicdaiya/slackboard

Slide 20

Slide 20 text

࣮ߦྫ $ slacklog -c test --log-channel test -- perl -E '$|=1;say "Hello";sleep 3;die' [2018-02-25T01:09:51][21066] *hostname* starting: perl -E $|=1;say "Hello";sleep 3;die [2018-02-25T01:09:51][21066] Hello [2018-02-25T01:09:54][21066] Died at -e line 1. [2018-02-25T01:09:54][21066] command exited with code:255 $

Slide 21

Slide 21 text

࣮ߦྫ(slack) ىಈऴྃϩά ίϚϯυͷ STDOUT STDERR

Slide 22

Slide 22 text

ಋೖޮՌ • batchͷΤϥʔͷݕग़ͱ௨஌ͷଈ࣌ੑΞοϓ • ϝʔϧ͸஗͍ɺ΋͘͠͸ΈΒΕͯͳ͍ • αʔόαΠυΤϯδχΞͷslack channelʹ௚઀ૹ৴ɻ඼࣭ͷ޲্ • ϩάΛ/dev/nullʹࣺͯͳ͍ӡ༻͕Մೳʹ

Slide 23

Slide 23 text

ಋೖޮՌ • ʮ͋ͷcronىಈ͍ͯ͠·͔͢ʁʯʮࡢ೔ϦϦʔεͨ͠batchɺਖ਼͘͠ಈ͍ ͯ·͔͢ʁʯͷΑ͏ͳΤϯδχΞ͔Βͷ֬ೝґཔͷ࡟ݮ • τΠϧͷ๾໓

Slide 24

Slide 24 text

঎඼ Ӿཡ ཤྺ SERVICE

Slide 25

Slide 25 text

Ӿཡཤྺ • ͓٬༷ͷ঎඼ӾཡͷཤྺΛαʔόʹ֨ೲ • UX޲্ͱͱ΋ʹɺTimeline Personalizationͷσʔλ ͱͯ͠΋׆༻ • ঎඼ͷӾཡ͸਺ઍreq/sec
 PerlͰߏங͞Εͨ ServiceͰॲཧ

Slide 26

Slide 26 text

App App App App App NGINX API(Perl) Q4M Worker (Perl) browse_item_service NGINX API(Perl) Q4M Worker (Perl) browse_item_service MySQL MySQL memcached memcached memcached "ߋ৽" "ࢀর" cluster (2) DBߋ৽&ཤྺऔಘ (3) cache࡞੒ (1) enqueue (1) cacheऔಘ/missͨ͠ΒDB App App App App App memcached memcached memcached NGINX API(Perl) Q4M Worker (Perl) browse_item_service DNS-RR by consul

Slide 27

Slide 27 text

CPAN modules • API • Plack, Gazelle • Worker • Parallel::Prefork • ڞ௨ • JSON::XS, DBD::mysql, Cache::Memcached::Fast::Safe Web Application Framework͸ະ࢖༻ Plack::(Request|Response)΋࢖ͬͯͳ͍ XS moduleΛ׆༻ͯ͠଎౓޲্

Slide 28

Slide 28 text

Performance • API/Worker͸Scale Out͕Մೳ • GazelleʹΑΔAPIαʔό͸े෼ʹߴ଎ • ϘτϧωοΫ͸ MySQL ͷϨϓϦέʔγϣϯ஗Ԇ • ௨ৗͷϨϓϦέʔγϣϯͰ͸਺ઍ transaction/s Ͱ஗Ԇൃੜ • MySQL 5.7ͷ Multi Thread Slave Λར༻ͯ͠΋ 18,000 t/s ͕ݶք • Sharding Λॳظઃܭʹ૊ΈࠐΈ

Slide 29

Slide 29 text

Performance (newRelic) ঎඼͝ͱͷPVΛܭଌ ͢Δ Service (Golang) Avg time: 3 msec Ӿཡཤྺ Service (Perl) Avg time: 4 msec PHP DBͳͲ

Slide 30

Slide 30 text

http://tech.mercari.com/entry/2018/02/26/110237

Slide 31

Slide 31 text

Կނ Perl?

Slide 32

Slide 32 text

ͳͥ Perl ? • kazeburo͕ॻ͍͔ͨΒ • System Call friendly ‣ OS ΍ ProcessɺNetwork ͷجૅΛֶͿͷʹద͍ͯ͠Δ • (Core Module ͷΈͰ࡞Ε͹) Deploy ͕༰қ • PerlͰഓΘΕٕͨज़ͷܧঝ ‣ mixi, livedoor (LINE), DeNA, ͸ͯͳ ͳͲେن໛WebαʔϏεΛࢧ͑ͯ(͍Δ|͖ͨ)ݴޠ

Slide 33

Slide 33 text

͜Ε͔Β • ϚΠΫϩαʔϏεɾίϯςφத৺ͷInfrustructure΁ • Serverlessɺk8sʹΑΔࣗಈԽ͞Εͨ Infrastructure • OS΍networkͳͲγεςϜΤϯδχΞϦϯάͷ஌͕ࣝ։ൃऀ͔Βԕ͘ͳΔ • Golang த৺ɺPerl ΠϯλϓϦλ͕ͳ͍؀ڥ

Slide 34

Slide 34 text

͜Ε͔Β • SREݚमͰPerlΛ৮ͬͯ΋Β͏ • ৽ଔ޲͚ʹ1ϲ݄͔Β1ϲ݄൒ఔ౓ͷSREݚमΛߦ͍ͬͯΔ • ͦͷதͰͻͱͭ͸PerlΛ࢖ͬͨ࢓૊Έʹ৮ΕΔػձΛͭ͘Δ • slacklogͷىಈϩάΛSlackʹૹΔػೳ͸SREݚमͰ࡞ͬͯ΋Βͬͨ΋ͷ • OSɾFile SystemɾProcessɾNetworkͱ͍ͬͨ௿ϨΠϠʔ΁ͷڵຯɾؔ৺
 UNIX ఩ֶʹ৮ΕΔػձ • ٕज़ͷఈ্͛ʹඞཁͳݴޠͷҰͭ

Slide 35

Slide 35 text

Ҏ্ careers.mercari.com/job/