yapc

46
Copyright 2009 © mixi,Inc. All right reserved. 1 株式会社ミクシィ 開発部 プラットフォーム開発チーム 田中 洋一郎 Webエンジニアのためのmixiアプリ開発ガイド

Upload: yoichiro-tanaka

Post on 21-Jan-2015

1.682 views

Category:

Documents


2 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  1

株式会社ミクシィ 開発部 プラットフォーム開発チーム

田中 洋一郎

Webエンジニアのためのmixiアプリ開発ガイド

Page 2: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  2

自己紹介

•  田中 洋一郎 – 株式会社ミクシィ所属

• 開発部 プラットフォーム開発チーム – Google API Expert (OpenSocial) – Mashup Award 3rd トリプル受賞

Page 3: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  3

アジェンダ

•  mixiアプリとは •  仕組み •  リリース時の出来事 •  安定したmixiアプリ •  まとめ

Page 4: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  4

注意事項

•  Perlの話は、ほとんど出てきません。

Page 5: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  5

『mixiアプリ』とは

Page 6: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  6

オープン化

利用者 mixi, Inc 開発者

Page 7: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  7

mixi Platform

2008年8月20日リリース済み -OpenID ver2.0に準拠 -mixi独自認証方式も提供 (マイミクシィ認証、コミュニティ認証)

2009年8月24日 mixiアプリ(PC) 一般ユーザー向けリリース開始!

-OpenSocial準拠

一部法人様へ提供 -OAuth認証

“mixiの中”にサービス・アプリケーションを開発し、提供できる仕組み。

“mixiの外”のWebサービスやデバイス等と連携できる仕組み。

“mixi”のユーザー情報(ID・PW)を外部サイトの認証に利用できる仕組み。

Page 8: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  8

一般公開

Page 9: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  9

常に新鮮で継続的なユーザ体験

Person & Friends API Community API

Activities API

Persistence API gadgets. io API

Invite API Albums API

Page 10: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  10

mixiアプリ ランキング

•  9月8日現在 – 公開アプリ数: 231

– 1位:通信制 脳力大学-漢字テスト(ドリコム) •  User数: 395,598

– 2位:マイミクテトリス(テトリスオンライン) •  User数: 218,529

– 3位:みん顔!(サイバード) •  User数: 163,740

Page 11: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  11

バイラルの仕掛け

Invite(インバイト)

アプリへの招待が1件あります!

このアプリは一緒に使うと面白そう!

お、招待がきてる!やってみるか~

Page 12: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  12

バイラルの仕掛け

アクティビティフィード(マイミクの更新情報)

アプリ更新情報

Page 13: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

OpenSocial

13

OpenSocial v0.8.1 + mixi独自API

Page 14: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリとOpenSocial

14

mixiアプリ(PC向け) (OpenSocial JavaScript API)

mixiアプリ(モバイル向け) (OpenSocial RESTful Protocol)

Page 15: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリ(PC版)

15

<?xml version=“1.0” encoding=“utf-8”?> <Module> <ModulePrefs title=“Hello, world!”> <Require feature=“opensocial-0.8” /> </ModulePrefs> <Content type=“html”><![CDATA[

<div>Hello, mixiアプリ!</div>

]]></Content> </Module>

Person & Friends API

Activities API

Persistence API

gadgets.io API

Gadget XML

XML + HTML + JavaScript + Flash

mixiアプリ

Invite API

Albums API

Page 16: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリ(PC版)

16

<?xml version=“1.0” encoding=“utf-8”?> <Module> <ModulePrefs title=“Hello, world!”> <Require feature=“opensocial-0.8” /> </ModulePrefs> <Content type=“html”><![CDATA[

<div>Hello, mixiアプリ!</div>

]]></Content> </Module>

Webサーバ

function init() { var req = opensocial.newDataRequest(); req.add(req.newFetchPersonRequest( opensocial.IdSpec.PersonId.VIEWER), “viewer”); req.send(function(data) { var viewer = data.get(“viewer”).getData(); // do something… } } gadgets.util.registerOnLoadHandler(init);

開発者が作成したファイル群

アップロード

URLを登録

読み込み・解釈

実行

開発者

ユーザ

mixiアプリ

Page 17: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリ(モバイル版)

17

<?xml version=“1.0” encoding=“utf-8”?> <Module> <ModulePrefs title=“Hello, world!”> <Require feature=“opensocial-0.8” /> </ModulePrefs> <Content type=“url” view=“mobile” href=“http://example.com/” /> </Module>

Person & Friends API

Activities API

Persistence API

Gadget XML

HTML + Flash + RESTful API

mixiアプリ

Albums API

Page 18: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリ(モバイル版)

18

リクエスト

レスポンス

リクエスト

プロフィール情報・ソーシャルグラフにアクセス

RESTful Protocol + OAuth

レスポンス

Page 19: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

Gadget XMLファイル

19

<?xml version=“1.0” encoding=“utf-8”?> <Module> <ModulePrefs title=“Hello, world!”> <Require feature=“opensocial-0.8” /> </ModulePrefs>

<Content type=“html” view=“home,canvas,profile”><![CDATA[ <div>Hello, mixiアプリ!</div> ]]></Content>

<Content type=“url” view=“mobile” href=“http://foo.com/hello.pl” />

</Module>

PC用

モバイル用

PC/モバイル両対応アプリを記述可能

Page 20: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  20

仕組み

Page 21: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

OpenSocial対応

•  必要となる実装 – Social Data API

•  /people, /activities, /appdata, JS(opensocial.*) – Gadget APIの実装

•  /gadgets/makeRequest, JS(gadgets.*) – Gadget Renderingの実装

•  /gadgets/ifr

21

Page 22: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

OSSの利用

22

•  Apache Shindig –  Apache Incubatorにて活動中のOSS

–  元々iGoogleのサーバソフトウェア –  初期コミットは2007年12月12日

–  現在もGoogler初め多くのコミッタやコントリビュータが参加 –  Java版、PHP版の並行開発

Shindig  -­‐    an  Apache  incubator  project  for  OpenSocial  and  gadgets  

http://incubator.apache.org/shindig/

Page 23: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

一般的なOpenSocial対応

23

/gadgets/ifr /gadgets/makeRequest /social/data/people /social/data/activities /social/data/appdata

SNSサーバ

データベース ・ プロフィール情報 ・ ソーシャルグラフ ・ アクティビティ ・ アプリデータ

Page 24: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixi Platform

24

/gadgets/ifr /gadgets/makeRequest

Main

データベース ・ プロフィール情報 ・ ソーシャルグラフ ・ アクティビティ ・ アプリデータ

/social/data/people /social/data/activities /social/data/appdata

API

(Java版)

(Perl)

Page 25: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

API Server

25

/social/data/people /social/data/activities /social/data/appdata

API (Perl)

apache mod_perl

memcached MySQL

balancer

Page 26: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

API Server

26

/social/data/people /social/data/activities /social/data/appdata

API (Perl)

Server Handler::People

Handler::Activity

Handler::AppData

people: uri: /social/data/people/{guid}/{selector} handler: People activity: uri: /social/data/activities/{guid}/{appid}/{selector} handler: Activity appdata: uri: /social/data/appdata/{guid}/{appid}/{selector} handler: AppDAta

socialdata.js

Accept: application/atom+xml ・・・ Atom Feed/Entry Accept: application/json ・・・ JSON

RESTful Protocol

Page 27: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  27

リリース時の出来事

Page 28: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

サーバダウン、応答時間低下

•  8/24~8/31 – mixiアプリ起動失敗 – APIレスポンス時間低下、停止

28

Page 29: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

Shindigダウン

•  Shindigのダウン – mixiアプリのレンダリングに失敗

•  504エラーの頻発

– Shindigの不具合 • 外部との通信がcloseされていなかった

– OSの上限に達し、以降の通信に全て失敗

• 修正を施し、以降安定して稼働

29

Page 30: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

APIダウン

•  APIのダウン –  /social/data/*の応答が遅くなる、停止

•  mixiアプリが起動しない • レンダリングされても何も起きない

– APIは比較的重い処理 • 複雑なパーミッションモデル •  mixiアプリの富豪的プログラミング

30

API

Page 31: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

APIダウン

31

mixi Platform パーミッションマトリクス

Page 32: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

APIダウン

•  サーバ台数追加により対処 – 初期台数の4倍近く追加!

•  1回目追加: 2倍 •  2回目追加: 4倍

– 根本解決が必要 •  CPU: 100%が継続

32

API

Page 33: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

APIダウン

•  Devel::NYTProf

33

API

Page 34: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

APIダウン

•  処理効率の向上に成功 – 当初の台数にて稼働可能

• キャッシュヒット率の向上 •  DBアクセスの削減 • 処理順序の見直し

– 仕様変更なし

34

API

Page 35: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリダウン

•  負荷に耐えられないmixiアプリ続出

35

時間

安定稼働度

mixi Platform

mixiアプリ

Page 36: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリダウン

•  負荷に耐えられないmixiアプリ続出 – mixi Platformが軽くなる – mixiアプリの利用が増える – バックエンドサーバへの要求が増える – mixiアプリが動かなくなる

36

→ いまここ

Page 37: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  37

安定したmixiアプリ

Page 38: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリの安定稼働

•  Person & Friends API •  ライブラリの利用 •  Activity + MediaItem •  バックエンドサーバ

38

Page 39: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリの安定稼働

•  Person & Friends API – 取得件数

•  startIndex + countの指定 –  count=1000なんて、もってのほか

•  hasAppフィルタの指定 – アプリ持ってないユーザの情報、本当に必要?

– 取得項目 •  fieldsの指定

– 全部取得して必要なものだけ使用、は御法度 – パーミッション検査処理の軽減

39

eco

Page 40: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリの安定稼働

•  ライブラリの利用 – 犠牲となる面を決して忘れない

• 暗黙的なパラメータ値の指定が問題 • 知らず知らずに富豪的プログラミング

– ライブラリの挙動を知る • 開発者に聞く、ドキュメントを読む •  OSSであれば、コードを読む

– ライブラリ作者の方々へ • 暗黙的な設定 → NG 簡単な設定 → OK

40

eco

Page 41: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリの安定稼働

•  Activity + MediaItem – Activitiyに含めた「画像」は、あなたのもの

41

eco

アプリ更新情報

バックエンドサーバ

makeRequestを受けるサーバ 画像を配信するサーバ ・・・に分けて負荷分散する、など

Page 42: Yapc

Copyright 2009 © mixi,Inc.  All right reserved. 

mixiアプリの安定稼働

•  バックエンドサーバ – アプリの人気が出るほどリクエスト増

• スケールするための仕組みが必要 •  mixi = mod_perl + memcached + MySQL

– クラウドサービスの利用 •  Google AppEngine •  Amazon EC2, S3

42

eco

Page 43: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  43

まとめ

Page 44: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  44

mixi Developer Centerのご案内

mixiアプリをご提供いただくソーシャルアプリケーションプロバイダ様向けに、下記サイトにて、情報提供を行っております。 今後、情報を随時更新して参りますので、ご確認ください。

(ミクシィデベロッパーセンター)

http://developer.mixi.co.jp/

Page 45: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  45

最後に

皆様におかれましては、 mixiアプリのご検討、ご展開をいただき、

この試みをご一緒に進めて参りたいと存じます。

どうぞよろしくお願いいたします。

mixi Platform、mixiアプリを通じて、 新たな市場・mixiを創造して参ります。

Page 46: Yapc

Copyright 2009 © mixi,Inc.  All right reserved.  46