SlideShare a Scribd company logo
5分では終わらなかった
Azure Functionsの話
2017 / 10 / 07 (土) 16:00~
.NET Conf 2017 Tokyo, Japan
Room C+D セッション3
谷口 慈行
• 先月JAZUG7周年でLTした内容で話したりないところ中心に
• ↑ 達成率 8 / 33 ページ
• https://www.slideshare.net/yiwate/5functions-79580540
About me
• 谷口 慈行(Yoshiyuki Taniguchi)
• @_iwate
• 人形町でECプラットフォーム作ってます
• https://www.commerble.com/
今日話さないこと
• Serverless Archtectureでどうやってアプリケーションを組むか
• 鉄板パターン&アンチパターンなど
• → .NETより抽象的な話なるのでなし
• Functionsを使った開発の話
• → うーん.NET?
• 運用回り
• → .NET?じゃないな
• Igniteでのアップデート内容
• https://buchizo.wordpress.com/2017/09/26/azure-update-ignite-
announcements-2017-09-25/
ちょっと待って!
話すことなくない?
今日話すこと
App Services
Function Host Function Host
Function Function Function Function Function
こっちの話をメインに。
Azure Functions
そもそもAzure Functionsって?
https://azure.microsoft.com/ja-jp/services/functions/
Azure Functions
• Github - https://github.com/Azure/azure-webjobs-sdk-script
• WebJobsベース、WebJobsのスクリプト拡張といってもいい
• いろんなスクリプトをイベントドリブンで実行
• js
• ps1
• csx
• …
• スクリプトじゃないものも
• dll
• jarNEW
Functionsで.NET
csx
Pre
Compiled
Direct
function.jsonにバインド情報を書く
csxファイルをコンパイルして実行
function.jsonにバインド情報を書く
事前にコンパイルしたdllから実行
Attributeでバインド情報を書く
事前にコンパイルしたdllから実行
NEW
Functionsで.NET
csx
Pre
Compiled
Direct
function.jsonにバインド情報を書く
csxファイルをコンパイルして実行
function.jsonにバインド情報を書く
事前にコンパイルしたdllから実行
Attributeでバインド情報を書く
事前にコンパイルしたdllから実行
Functionsで.NET
csx
Pre
Compiled
Direct
function.jsonにバインド情報を書く
csxファイルをコンパイルして実行
function.jsonにバインド情報を書く
事前にコンパイルしたdllから実行
Attributeでバインド情報を書く
事前にコンパイルしたdllから実行
Functionsで.NET
csx
Pre
Compiled
Direct
function.jsonにバインド情報を書く
csxファイルをコンパイルして実行
function.jsonにバインド情報を書く
事前にコンパイルしたdllから実行
Attributeでバインド情報を書く
事前にコンパイルしたdllから実行
正直なんて呼べばいいのかわからない。ソースコード内ではDirectと呼ばれているのでとりあえず。
もしかすると、WebJobスタイルとかAttributesスタイルとかかも
• Pre-compiledの一方式として属性でバインドできるようになっ
たんじゃないの?
• 理由はそうかも?
• それらしいISSUEやFeedbackは見つからなかったけど…
• でも、実装はだいぶかけ離れてる
• Pre-compiledはcsxスタイルの方が近い
Direct ⊄ Pre-compiled
csxの取り込まれ方
{
“bindings” : [
{ “name” : “trigger”,
“type” : “queueTrigger”, … },
{ “name” : “original”,
“type” : “blob” , … },
{ “name” : “resized”,
“type” : “blob”, … }
]
}
FunctionMetadata
FunctionGenerator
namespace Host {
public class Functions {
public static Task Run(
[QueueTrigger(…)]string trigger,
[Blob(…)] string original,
[Blob(…)] ref string resized,
TraceWriter log){…}
}
}
[QueueTrigger(…)]
[Blob(…)]
[Blob(…)]
FunctionDescriptor
① function.jsonからFunctionMetadaを作成
② function.jsonからFunctionMetadaを作成
③ FunctionMetadaからAttributeを作成
④ MetadataとAttiributeから
Descriptorを作成
TraceWriterなどの
パラメータを追加
⑤ Descriptorからアセンブリを作成
• https://github.com/Azure/azure-webjobs-sdk-
script/blob/master/src/WebJobs.Script/Description/Functio
nGenerator.cs
• 中ではILで組み立ててる
FunctionGenerator
• あっちもこっちもILですね。
FunctionGeneratorを読んでみる
FunctionGeneratorを読んでみる
FunctionGeneratorを読んでみる
namespace Host {
public class Functions {
public static Task Run(
[QueueTrigger(…)]string trigger,
[Blob(…)] string original,
[Blob(…)] ref string resized,
TraceWriter log){}
}
}
FunctionGeneratorを読んでみる
namespace Host {
public class Functions {
public static Task Run(
[QueueTrigger(…)]string trigger,
[Blob(…)] string original,
[Blob(…)] ref string resized,
TraceWriter log){
object[] argsLocal = new object[]
{
trigger,
original,
resized,
log
};
}
}
}
FunctionGeneratorを読んでみる
namespace Host {
public class Functions {
public static Task Run(…){
object[] argsLocal = new object[]
{
trigger, original, resized, log
};
IFunctionInvoker invokerLocal
= GetInvoker("Resize");
var taskLocal
= invokerLocal.Invoke(argsLocal);
}
}
}
MethodInfo.Invokeのラッパー
FunctionGeneratorを読んでみる
namespace Host {
public class Functions {
public static Task Run(…){
object[] argsLocal = new object[]{…};
IFunctionInvoker invokerLocal
= GetInvoker("Resize");
var taskLocal
= invokerLocal.Invoke(argsLocal);
taskLocal.GetAwaiter().GetResult();
resized = argsLocal[2];
return taskLocal;
}
}
}
• FunctionGenerator.cs 127行目~155行目を使う
• Load Local命令は、手👏
• Store Local命令は、足👞
• それ以外は、机
ICE BREAK: ILのビートを感じてみよう
• FunctionはWebJobベース
• FunctionのScriptHostはWebJobのJobHostを継承して作っている
• WebJobにもともと色々なトリガーによるイベントドリブンに
実行できる関数を作れた。
• .NETの関数を実行する仕組みは新たに作らず、WebJobのもの
をそのまま使ってる。
• だから、Functionの仕事はWebJobスタイルのAttributeでバイ
ンド情報が付与された関数を作ること
重要なのはcsxもAttributeを作っていること
• csx とPre Compiledはコンパイルするかしないかだけの違い
• 同じようにGeneratorの中で、Attributeが付与された関数が作られる
• DirectはGeneratorでラッパーを作らず、読み込んだアセンブ
リの関数を直接使用する
• そもそも、Attributeがついているのでラップする必要がない
csx, Pre-compiled, Directの違い
csxとアセンブリ
ロード方法
#r "Newtonsoft.Json"
#r "Taniguchi.dll"
#r "../sharedbin/Yoshiyuki.dll"
using System;
using Taniguchi;
using Yoshiyuki;
using Newtonsoft.Json;
using SumLib.From.NuGet;
public static Sample Run(
string message,
TraceWriter log)
{
}
Hostが持ってるものをロード
最初からロードされている
binフォルダーからロード
project.jsonでNuGetから取得したやつ
CurrentPathから相対パスでロード
ロード方法
#r "Newtonsoft.Json"
#r "Taniguchi.dll"
#r "../sharedbin/Yoshiyuki.dll"
using System;
using Taniguchi;
using Yoshiyuki;
using Newtonsoft.Json;
using SumLib.From.NuGet;
public static Sample Run(
string message,
TraceWriter log)
{
}
Shared Assembly
Default Assembly
Private Assembly
Package Assembly
External Assembly
Direct同様なんて呼んでいいかよくわからない。
とりあえず、ソースコードから雰囲気で抽出
ロード方法
#r "Newtonsoft.Json"
#r "Taniguchi.dll"
#r "../sharedbin/Yoshiyuki.dll"
using System;
using Taniguchi;
using Yoshiyuki;
using Newtonsoft.Json;
using SumLib.From.NuGet;
public static Sample Run(
string message,
TraceWriter log)
{
}
Shared Assembly
Default Assembly
Private Assembly
Package Assembly Assembly.LoadFile
Assembly.Load + assembly.MapCodeBase
Assembly.LoadFrom
typeof().Assembly | Assembly.LoadFrom
typeof().Assembly
External Assembly
アセンブリのロードのされ方が割と違う
Default Assembly と Shared AssemblyはRoslynのScriptOptionに、
他はAppDomain.CurrentDomain.AssemblyResolveにResolverにラップされてわたされる
ロードのされ方って別にどうでもよくない?
• よくない場合があるので注意しよう
• Assembly.Loadで取り込まれるPrivate Assembly(binフォル
ダ)のLocationプロパティが空文字になる。
• https://msdn.microsoft.com/ja-
jp/library/system.reflection.assembly.location(v=vs.110).aspx
• Locationプロパティを触るライブラリを使ってるときは思わぬ
沼にはまることがある。
Dynamic Assembly Load
• Razor Engine みたいな動的にアセンブリを読み込むライブラリ
は配置場所を考える必要がある
• binフォルダから読まれたアセンブリではAssembly. Locationが
空文字になり、Illegal Path例外で落ちる(Assembly.Loadだか
ら)
• しかも、External Assemblyでもたまに空文字になる(原因わ
からず)
• つまりIllegal Pathは完全には防げない
• いったんIllegal Pathになると再起動しないと直らない(直らなかっ
た)
• AppServiceの停止や再起動時にはCancellationToken.Noneな
のでGraceful Shutdownできない
• WebJobsでいうSoft shutdownの時だけ
• https://github.com/projectkudu/kudu/wiki/WebJobs#graceful-
shutdown
• コンパイルとかFunction Host内で動いてるFunctionをいった
ん止めるときとかだけ。
• あんまり、 Graceful Shutdownが必要なものは載せない方がい
いと思う。
再起動と言えばGraceful Shutdownの話
まとめ
• csx, Pre-compiled, Direct は結構違う
• 結局最後はDirectの形
• Direct使うんなら、WebJobでもそんなに変わらない
• モニターとかHttpTrigger、プロキシとか違うとこももちろんある。
• Functions
• 何より従量課金プランがある!(これがないとサーバーレス感半減)
• Webjob
• MainでJobHost生成して使用するので、WebJobsShutdownWatcherとか使える
• コード読むの楽しい
まとめ

More Related Content

PDF
Apache Airflow入門 (マーケティングデータ分析基盤技術勉強会)
PDF
PDF
Fission で 始める Containerless Kubernetes #serverlesstokyo
PDF
静岡のHaskellerはEmacsを使う
PDF
The Generator of ECMAScript 6th
PDF
Phpでrest apiを作った話
PDF
serverless framework + AWS Lambda with Python
PDF
20140930 anything as_code
Apache Airflow入門 (マーケティングデータ分析基盤技術勉強会)
Fission で 始める Containerless Kubernetes #serverlesstokyo
静岡のHaskellerはEmacsを使う
The Generator of ECMAScript 6th
Phpでrest apiを作った話
serverless framework + AWS Lambda with Python
20140930 anything as_code

What's hot (20)

PDF
Reflexの紹介
PDF
Fabric
PDF
PHPコードではなく PHPコードの「書き方」を知る
PDF
DynamoDBのまえにキャッシュおく奴
PDF
WebAPIのバリデーションを、型の力でいい感じにする
PDF
Active job meets kubernetes
PPTX
Webブラウザで使える文献Web API取得結果のスプレッドシート化 ~ Google Colab始めました ~
PDF
The Next Generation for C# Developers
PDF
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
PPTX
当番をランダムに割り当ててみる ~ on-dutyTable.py ~
PDF
Ruby/Rails Benchmarking and Profiling with TDD
PDF
これからのJavaScriptー関数型プログラミングとECMAScript6
PDF
Apache Airflow で作る GCP のデータパイプライン @ 酔いどれGCPUG 2017/11/28
PDF
ECMAScript6による関数型プログラミング
PPT
20150219 初めての「embulk」
PDF
Ruby風Swift NSOperation編
PDF
Lambdaによるクラウド型言語の実装
PPTX
Gitlab meetup prm説明資料_2017_1117
PDF
Heroku+MongoLabでダミーサーバー
PDF
動的なILの生成と編集
Reflexの紹介
Fabric
PHPコードではなく PHPコードの「書き方」を知る
DynamoDBのまえにキャッシュおく奴
WebAPIのバリデーションを、型の力でいい感じにする
Active job meets kubernetes
Webブラウザで使える文献Web API取得結果のスプレッドシート化 ~ Google Colab始めました ~
The Next Generation for C# Developers
JavaScriptCore.framework の普通な使い方 #cocoa_kansai
当番をランダムに割り当ててみる ~ on-dutyTable.py ~
Ruby/Rails Benchmarking and Profiling with TDD
これからのJavaScriptー関数型プログラミングとECMAScript6
Apache Airflow で作る GCP のデータパイプライン @ 酔いどれGCPUG 2017/11/28
ECMAScript6による関数型プログラミング
20150219 初めての「embulk」
Ruby風Swift NSOperation編
Lambdaによるクラウド型言語の実装
Gitlab meetup prm説明資料_2017_1117
Heroku+MongoLabでダミーサーバー
動的なILの生成と編集
Ad

Similar to Dotnetconf2017 (20)

PDF
5分では終わりそうにないfunctionsの話
PPTX
Azure Function GAした!Visual Studio Tools for Azure Functions もプレビューだ!
PDF
ゆるふわAzure Functions
PPTX
PythonによるAzureサーバレスアプリケーション開発 / Serverless Application Development with Python
PPTX
Azure Functions あれこれ
PPTX
Azure serverless!! azure functionsでサーバーを意識しない開発
PDF
Azure Functions 入門
PPTX
Visual Studio 2017 で Azure Functions の開発
PDF
Azure Functionsでサーバーレスアプリケーション構築
PPTX
azure functionsとcsx
PDF
Azure Functionsでサーバーレスアプリケーション構築
PDF
20190514 Smart Store - Azure servlerless architecture
PDF
Smart Store サーバーレスアーキテクチャ編
PDF
.NET Framework アプリケーションの NET 5 への 移行を考える
PDF
Azure Functions と Serverless - 概要と企業向け Tips
PDF
[Japan Tech summit 2017] APP 003
PDF
Application development with c#, .net 6, blazor web assembly, asp.net web api...
PPTX
Blazor WebAssembly と Windows Forms でのロジック共有例
PDF
20190731 Azure Functions x Line at Azure Tech Lab #4
PDF
Application development with c#, .net 6, blazor web assembly, asp.net web api...
5分では終わりそうにないfunctionsの話
Azure Function GAした!Visual Studio Tools for Azure Functions もプレビューだ!
ゆるふわAzure Functions
PythonによるAzureサーバレスアプリケーション開発 / Serverless Application Development with Python
Azure Functions あれこれ
Azure serverless!! azure functionsでサーバーを意識しない開発
Azure Functions 入門
Visual Studio 2017 で Azure Functions の開発
Azure Functionsでサーバーレスアプリケーション構築
azure functionsとcsx
Azure Functionsでサーバーレスアプリケーション構築
20190514 Smart Store - Azure servlerless architecture
Smart Store サーバーレスアーキテクチャ編
.NET Framework アプリケーションの NET 5 への 移行を考える
Azure Functions と Serverless - 概要と企業向け Tips
[Japan Tech summit 2017] APP 003
Application development with c#, .net 6, blazor web assembly, asp.net web api...
Blazor WebAssembly と Windows Forms でのロジック共有例
20190731 Azure Functions x Line at Azure Tech Lab #4
Application development with c#, .net 6, blazor web assembly, asp.net web api...
Ad

Dotnetconf2017

Editor's Notes

  • #2: それでは、はじめます。 こんなに人いると緊張しちゃいますね。 緊張するとおなか壊すタイプなので今日はしっかり胃薬飲んできました。 セッションタイトルなんことじゃいって感じだと思うんですけど 改ページ
  • #3: このまえ、先月ですかね。 AzureユーザーグループでLTしたんですけど、その時、5分じゃ到底終わりそうにない資料作っちゃって、それをもじってます。 でも、今回のスライドは大体新規書き起こしです。こぴってるのもありますけど。
  • #4: 自己紹介は。。。飛ばしましょう
  • #5: さて、今日はDotNet Confということなので、話す内容をかなり絞ろうかなと思いまして、結構考えたんですけど、 次の項目は全部そぎ落としてみようと思います。 時間余ったら登場してもらうこともあるかもしれませんが。 サーバーレスアーキテクチャの話とか、Functionsでどんな風にアプリケーション組んでいくかとかCI/CDの 話とか ログ監視とかの運用回りとか、 開発パターン系とか。
  • #29: 終わったら いやあ、皆さん素晴らしい! 最高のILビートでした。ビシビシ来ましたよ。 懇親会の時、隣の部屋の人から 「一体何してたの?」 って聞かれたら、 「ILのビートを感じていたのさ」とぜひお答えください。