SlideShare a Scribd company logo
1 of 24
Download to read offline
Lambdaでクローリング
2017/07/21
サーバレスアーキテクチャを勉強する会
株式会社ゴーリスト 盛次経王
自己紹介
• 盛次 経王(モリツグ ツネオ)
• 株式会社ゴーリスト所属
• クローラからフロントまで手広く色々
やってます
• フロントではAngular、サーバサイド
ではJavaが多いです
• 今日はスプラトゥーン2の発売日です
ゴーリストについて
ゴーリストについて
この辺を担当したり関わったりしてます
Redshift
HRogチャートのサーバレス構成
OZで蓄積した求人データをエリア、職種、給与などで検索、集計できる
Redshiftには2億4千万件(カラム数53) のテーブルがある
LambdaAPI Gateway
S3
HRogチャートでみるメリットデメリット
知ったように喋っていますが、実はHRogチャートはフロント
側の実装担当だったので裏側はそこまで詳しくないです。
なので、担当者に聞いてきました。
HRogチャートでみるメリットデメリット
メリット
Lambda、RedshiftともにAWSの東京リージョンなので、クエリ結果が
返ってくるのが早い(と思う。計測したわけではないです。)
↑Lambdaの代わりにEC2を使っても同じだとは思うので、アプリケー
ションサーバーとDBをAWSで統一するメリットと言う感じですが。
デメリット
Lambda と API Gatewayを使っているので、Redshiftに重いクエリ(一つ
のテーブルから仕事内容、応募内容などの長い文字列を含む20列くらい分
の求人案件レコードを200件取ってくるみたいなクエリ)を投げるとAPI
Gatewayのレスポンス時間制限(30秒)に引っかかりレスポンスが返せない
場合がある。
要約すると...
HRogチャートでみるメリットデメリット
メリット
統一感
デメリット
API Gatewayの30秒制限つらい
RedshiftやAPI Gatewayがボトルネック
Lambdaは何も悪くない
Redshiftの同時接続数の上限は動的には増やせない
HRogチャートはサーバレスでちゃんと動いている
Lambdaはもっと可能性を秘めているのではないか?
Lambdaのコスト
512MBで100時間使った場合
100 × 3600 × 0.000000834 × 10 = 3.0024 ($)
(無料枠は512MBでは800,000秒=約222時間)
EC2のt2.micro(メモリ1.0GB)を100時間使った場合
100 × 0.016 = 1.6 ($) (無料枠は720時間)
...単純なコスト比較にはあまり意味が無い
Lambdaは「使った分だけ課金」なのでEC2インスタン
スが遊んでいる時間が長ければ圧勝しそう
Lambdaをクローラに使ってみる
• EC2で動いているクローラの一部をLambdaに変更する
• デイリーで50,000件(200,000リクエスト)ぐらいの民泊系サイト
• EC2インスタンス80台で同時取得
• クローラに厳しめで応答が遅くなったり、IP制限される
• インスタンスを停止してIPを変えて対応している
• クローラは Java + Selenium WebDriver + PhantomJS
Lambdaに変更した処理
• URLリストクロール(検索の結果ページなどを集める)
• URLリストのスクレイプ(取得したHTMLからURLを抜き出す)
• 50,000件の各URLを80台でクロール
• クローリングが終わったら各インスタンスでスクレイプ
ここだけLambdaにした
Lambdaでクローリングするための構成
Lambda S3
Website
DynamoDB
EC2
proxy & controller
invoke
・
・
・
crawl
check
update
update
save
EC2
ec2-rebooter
reboot
1. PhantomJSをLambda上で動くようにする
2. IP問題を解決する(IP制限をかわしたい)
3. VPC内のLambdaからS3やDynamoDBに接続する
※今回はLambdaをインターネット上ではなくVPC内に置く
Lambdaでクローリングできるまで
PhantomJSはGUI環境がなくてもうごく
ヘッドレスブラウザ
Lambdaにはfontなどは一切入っていないの
でほとんどの言語が文字化けする
PhantomJSをLambdaで動くようにする
詳細はゴーリストの技術ブログに書きました…
http://developers.goalist.co.jp/entry/2017/06/23/120000
ポイントは大体以下
• Lambdaにデプロイしたzipやjarは /var/task 以下に展開される
• /var/task/lib はLD_LIBRARY_PATHに指定されている
• chmodは使えないので実行権限は事前に与えておく
• phantomJSのログファイルの場所を /tmp 以下に変更する
1. LambdaFunctionをわければ違うインスタンス(IP)になる?
IP問題を解決する(IP制限をかわしたい)
同じLambdaインスタンスが使われる。
同時リクエストが一定数を超えてオートスケーリングすると変わる。
2. LambdaFunctionを複数用意してVPCをわければ何とかなる?
使っていい金額とリマップの頻度次第ではこれでいける。
VPC毎のNAT Gatewayに指定するElasticIPをリマップすればいい。
リマップは月間100回までは無料、それ以降は1回0.1$。
仕方ないので今回はt2.nanoを80個たててproxyサーバとした
...サーバレス?いいえLambdaです。
VPC内のLambdaからS3やDynamoDBに接続する
VPC内のLambdaからS3やDynamoDBに接続するには
1. NAT Gatewayを使ってインターネットアクセス
2. VPCエンドポイントを作ってアクセス
2017/07/21現在でS3はVPCエンドポイントに対応している、
DynamoDBはパブリックプレビュー
3. EC2インスタンスをproxyにしてインターネットアクセス
• 金額自体は1日30ドル前後でsmallを80台で動かしたと
きと大差なし。元のインスタンスが諸事情によりsmallであ
ることを考慮すると値段は高くなっている気がする(ぇ
• クローリングにかかる時間は元がマルチスレッドでは無
かったので同時実行数の分だけ短縮された。今回は同時実
行数3で8~10時間⇒2~3時間ぐらい
結果どうだったのか その1
• Webアプリと違ってバッチ処理のようなインスタンスが
遊んでいる時間が無く、マシンパワーをしっかり使い切
るような場合はコスト面ではEC2の方が有利。
• マルチスレッドでも出来ることをLambdaに置き換えた
だけな気もするが、複数サイトになった場合にスレッド
数に上限がない(性能も劣化しない)ことを考えると意
味があるように思う。強いインスタンス立てたりインス
タンスの上限緩和申請出さなくて良いし。。。
結果どうだったのか その2
• 最大時間が5分の縛りがあるので処理を小分けにすること
が必要とされる場面もある。また、クロールしたファイ
ルの取り扱いがEC2に比べるといちいち面倒。
DynamoDBに突っ込んでもいいが、S3に置く方が安い。
• 開発時のデバッグが辛い場合があったり、ログも
CloudWatchだけでは無理ゲーなのでS3にエクスポート
して解析したり一手間かかる。
結果どうだったのか その3
なんだかあと一歩な結果でしたが
これは私のサーバレス力が不足しているだけです
Lambdaには可能性しか感じません
以上です
ご清聴ありがとうございました

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

2017 0721 サーバレスアーキテクチャを勉強する会