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

pixivにおけるPlayとThrift

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

 pixivにおけるPlayとThrift

Play Meetup 2015

Avatar for Atsushi Takayama

Atsushi Takayama

July 05, 2015
Tweet

More Decks by Atsushi Takayama

Other Decks in Technology

Transcript

  1. ࣗݾ঺հ • ߴࢁ Թ @edvakf • pixivͷອըࣄۀͷ։ൃ੹೚ऀ • ීஈॻ͍ͯΔͷ͸Scala΍PHPɺͨ·ʹJS΍Ruby΍Go •

    ࠷ۙϦʔυΤϯδχΞͱ͍͏ݞॻʹ • ձࣾͷٕज़બ୒ʹ੹೚Λ࣋ͭ • ʮࣾ಺ͷΤϯδχΞ͕޾ͤʹಇͨ͘Ίʹ͸ʯΛߟ࣮͑ݱ͢Δۀ
  2. ScalaͱThrift • Thriftͷຊମ͸Javaαϙʔτ͕खް͍͕ɺScala͸ରԠͯ͠ͳ͍ • Twitterͷ࡞ͬͨScroogeͱ͍͏ͷ͕͋Δ • ࢖͓͏ͱࢥͬͯௐ΂ͨ࣌͸Scala 2.10·Ͱ͔͠αϙʔτ͍ͯ͠ͳ ͔ͬͨ •

    ࠓ͸2.11΋͋Δ͕ɺͦ΋ͦ΋࢖͍ํ͕Α͘Θ͔Βͳ͍orz • Finagleͱ߹Θͤͯ͡Όͳ͍ͱ࢖͑ͳ͍ʁ • →ૉ௚ʹJavaͷϥΠϒϥϦΛ࢖͏͜ͱʹ
  3. ࢖༻ྫ // Thrift service MyService { string someMethod(1:int input), }

    // Scala val transport = new THttpClient(url) val protocol = new TBinaryProtocol(transport) val client = new MyService.Client(protocol) transport.open() val output = client.getSomeMethod(input) transport.close()
  4. ඇಉظ൛ʢલ൒ʣ val sendTransport = new TMemoryBuffer(128) val sendProtocol = new

    TBinaryProtocol(sendTransport) val recvTransport = new TMemoryInputTransport() val recvProtocol = new TBinaryProtocol(recvTransport) val client = new MyService.Client(recvProtocol, sendProtocol) sendTransport.open() recvTransport.open()
  5. ඇಉظ൛ʢޙ൒ʣ client.sendSomeMethod(input) WS.url(url).withHeaders( "Content-Type" -> “application/x-thrift") .post(sendTransport.getArray) .map { response

    => recvTransport.reset( response.underlying[NettyResponse] .getResponseBodyAsBytes) val output = client.recvSomeMethod(input) } andThen { case _ => sendTransport.close() recvTransport.close() }