12. “Offline First is the new Mobile First”
by Michael Hart,
Senior Software Development Manager
Predix Experience, General Electric
13. Couchbase Connect 2015 GEセッション資料「Offline First: How GE Integrated Couchbase Mobile in Less Than 90 days」から引用
http://www.slideshare.net/Couchbase/offline-first-how-ge-integrated-couchbase-mobile-in-less-than-90-days-couchbase-connect-2015
14. Couchbase Connect 2015 GEセッション資料「Offline First: How GE Integrated Couchbase Mobile in Less Than 90 days」から引用
http://www.slideshare.net/Couchbase/offline-first-how-ge-integrated-couchbase-mobile-in-less-than-90-days-couchbase-connect-2015
15. Couchbase Connect 2015 GEセッション資料「Offline First: How GE Integrated Couchbase Mobile in Less Than 90 days」から引用
http://www.slideshare.net/Couchbase/offline-first-how-ge-integrated-couchbase-mobile-in-less-than-90-days-couchbase-connect-2015
16. The Motley Fool 「What Internet of Things (IoT) Investors Need to Watch in 2015」から引用
http://itpro.nikkeibp.co.jp/atcl/column/15/032400051/032400001/
17. GE公式ブログ「GE’s Industrial Internet Just Got Real: 14 New Applications That Could Boost
GDP by $10-15 Trillion」から引用http://blog.pivotal.io/pivotal/p-o-v/ges-industrial-internet-just-got-real-14-new-
applications-that-could-boost-gdp-by-10-15-trillion
既にご存知の方もいらっしゃるかもしれませんが、昨年10月にゼネラルエレクトリックはエネルギー、運輸(うんゆ)、航空、ヘルスケアなど40種類にも及ぶIoTソリューション「Predix(プレディクス)」の提供を開始しました。
GEはご存知の通り、医療、環境、重工業(じゅうこうぎょう)、航空運輸など様々な分野でビジネスを展開するグローバル企業ですが、これら業界向けにセンサーの設置、収集、分析、活用を目的としたサービスがこのPredixです。Predix開発のために1000人ものエンジニアを増員したという記事もありましたので、GEがこのIoTソリューションに非常に力を注いでいるのが分かります。(http://coin.nikkeibp.co.jp/coin/nis/1401/pdf/sample2.pdf)
そしてこのPredixを裏で支えているのがCouchbaseモバイルソリューションです。
サービス提供開始からわずか数ヶ月後にソフトバンクもこのPredix専用の海運(かいうん)や製造(せいぞう)分野向けアプリ開発のライセンスを契約していますので、日本の皆さんも気がつかないうちにCouchbaseのモバイルソリューションを使用しているかもしれません。(http://goo.gl/82wO3d)
それでは、Couchbaseモバイルソリューションの解説の前に、もう少しGEのIoT基盤Predixについてお話したいと思います。
GE, one of the largest companies in the world, operates several large business segments including Energy, Transportation and more.
In October 2014, they started to provide IoT platform called “Predix” for their customers such as medical/healthcare, environment, airplane, etc.
A report said that GE hired additional 1000 engineers for this project, and we can easily understand that GE is focusing a lot of resources on Predix.
And Couchbase Mobile Solution is supporting GE’s IoT platform.
Within a few months after the first release, the third largest telecom company, Softbank, had a license agreement to build mobile app for shipping or manufacturing on Predix.
So without being noticed, you might have already used our mobile solution though Predix.
So let me talk a little more about Predix before getting into Couchbase Mobile Solution.
-------------------------------------------------------------------------------------------------------------
*Below is Ali’s note;
What I’m going to talk about today is their Predix platform and how they use Couchbase Mobile to enable some really powerful capabilities.
Predix is GE’s software platform for the Industrial Internet. It connects things like trains, wind farms, submarines, and so much more. All kinds of things that are counted on to work all day, everyday for the next 25, 30, 35+ years...
Connectivity is mission critical – these machines are literally everywhere. The middle of the ocean, the top of a mountain, inside of a turbine, or in a rail yard. And even then, those machines have hundreds of moving parts, all of which need to be tracked and maintained.
So what Predix does is ingest all this data, stores it, cleans it, analyzes it and takes all of this critical information back to the operator. And it provides that information at massive scale. So Predix must be reliable, 24/7.
GEは2012年11月から今回のIoT基盤Predix開発のきっかけとなる「インダストリアル・インターネット」を提唱しています。
この図はITProの記事から引用させて頂いていますが、この図の通りインダストリアル・インターネットの中核である共通プラットフォームがPredixです。
このインダストリアル・インターネットとは、様々な製品から稼働データなどを収集してビッグデータを分析、運用し、保守や次の製品開発に生かす構想(こうそう)を意味します。
図にある通り、まずセンサーを埋め込んだ各種機器からネット経由で様々なビッグデータを安価に収集し蓄積します。
そしてそのデータの分析によって、機械の故障を事前に見極めたり、点検を促すなどして、現場でのアクションをより効率化することに繋がります。
GE has been proposing the idea called “Industrial Internet” since November 2012, and this is the core idea to develp Predix.
As you can see in the image, Predix is the core technology forming Industrial Internet. (sensors (devices) > big data (storage) > analytics (BI) > actionable info (mobile)
Industrial Internet means that sensors generated from industrial machines will be collected to database (data lake), then analyzed so that field engineers can make action for maintenance or sometimes even to improve their services in future.
Data can be also used to provide information to field engineers to check machines before they have problems.
それではGEの事業部門の一つであるトランスポーテーションシステムの例を見てみましょう。
GEはこの写真のような鉄道車両の製造(せいぞう)を行っており、そのビジネスをグローバルに展開しています。
日本では比較的通信環境が整っているので、最近では携帯を片手に持ち上げて電波を探し回るということもなくなってきました。
しかし海外では大きな都市でも電波が安定していない、繋がらないということは頻繁になります。
これは以前サンフランシスコの同僚が話していたことなんですが、「今サンフランシスコ市内の駐車場にいるんだけど、市内なのに電話が繋がらなくて流石に驚いたよ」とコメントしてました。
そのためこのような鉄道の車庫(だと思いますが)のような場所だと電波が繋がらないということはよくありがちなことです。
Let’s look at an example from one of GE’s businesses divisions: the transportation systems department. GE manufactures train engines and cars like the one in this picture around the world. In Japan, communications networks have advanced greatly so it’s not hard to find a signal, but abroad is another story. Frequently you will not be able to connect, even in a large city. This means that workers often find themselves in places with little to no connectivity, like this train yard.
これは鉄道が積み荷の運搬(うんぱん)のため、車庫からどのレールに配置されるかというオペレーションをイメージしています。
The rail yard worker is using this app, powered by Predix, to manage and direct these tasks.
鉄道の車庫周辺は電波が安定していないため、作業員がPredixのモバイル端末を使用して、貨車がどのレールに配置されるかコントロールします。
Because network connectivity is not reliable here, the worker will use a mobile tablet with the Predix app installed on it and control which car goes where.
貨物(かもつ)の配車になりますので,時間に遅れるわけにはいきません。
These cars are loaded with important cargo so they can’t afford to be late.
オンライン・オフラインに関わらず、いかなる環境でもオペレーションをスムーズに行う必要があります。
Operation needs to continue smoothly regardless or being online, offline, or whatever situation.
少し前から「Mobile First」という言葉を聞いてきましたが、GEのマイク・ハート氏が6月開催されたCouchbaseの米国カンファレンスでこのようなことをコメントしていました。
“Offline First is the new Mobile First”。
You may have noticed a catch phrase “Mobile First.” This is because of a quote from Michael Hart duringCouchbase’s U.S. conference. “Offline First is the new Mobile First.”
というのも、GEは産業機会を扱うため、この図のようなネット回線がない、または不安定な場所でエンジニアが作業にあたっているからという理由があります。
GE is always on the lookout for business opportunities, and workers often find themselves in situations like this where there is little to no network connectivity.
これは石油開発の様子です。海上での作業は陸地(りくち)よりもネット回線に不安があるかと思います。
This is an oil refinery, and as you might expect connectivity is a lot more scarce over the water than it is on land.
この図は石油パイプラインの作業現場です。このような制御室ではネットの環境が不安定なのですが、そんな中でもエンジニアは故障への対応などにあたらなければいけません。
Here is a shot inside the oil refinery. The network connectivity in this control room is not reliable but regardless of that the engineers have to continue working.
良く紹介される例では発電システムが挙げられるようなのですが、タービンの動きをネット経由でリアルタイムに監視し、故障の予兆を事前に見極めるというものがあるそうです。オペレーターが先回りして対処(たいしょ)に当たることができるので業務(ぎょうむ)が非常に効率的になります。またそれだけに留(とど)まらずこのビッグデータを利用して次の製品開発の改善にも役立てることにも繋がっています。
Another example that often comes up is power plants. The workers can monitor the movement of turbines and predict potential breakdowns in realtime. They are able to anticipate and deal with problems ahead of time so it’s extremely efficient. And that’s not all, they can aggregate this data and incorporate it into future development and improvement.
このイメージはGEの公式プログから引用していますが、ご覧の通りタブレット端末に保存されているイメージやデータで作業ができます。
オフラインで作業をしてオンラインになった時にデータを同期することが出来るのです。
This is an image from GE’s official blog. The image shows data being saved locally on the device so the worker can continue working. Once connectivity is restored, all the work they’ve done can be synchronized in the cloud. This leads us to an interesting development in mobile history.
ネットが繋がらない症状はGEの提供する鉄道、航空、環境ビジネスなどに限りません。
インターネットの繋がらない環境はもちろんですが、建物の中、飛行機など高いところ、地下鉄、カンファレンスや遊園地などネット利用者が密集(みっしゅう)している場所、年末年始などメッセージのやり取りする時間帯が通常より集中するケース、作業現場など遠隔地(えんかくち)で電波が安定していない場所、更に基地局(きちきょく)の隙間(すきま)や、逆に基地局が多いところでも電波同士の干渉(かんしょう)でネットに繋がりにくくなることもあります。
このような電波が繋がりにくい場所でも、業務中やプライベートに関わらずモバイル端末を使用する必要は出てきます。
The problem with Internet connectivity is not limited to GE’s industrial service such railway, airplane, or oil/gas business.
There are a lot of places where internet connections are unstable such as; inside building, in a airplane, subways, crowded places like conference room or theme park, specific event date/time like New Year’s as many greeting messages, field work places, between base station antenas, or even where there are too many base station antenas.
With or without internet connectivity, business or private, mobile app needs to keep running so that people are comfortable of using it.
このように電波に依存していては繋がったり、繋がらなかったりではなかなか作業が はかどりません。
オンライン・オフラインに関わらずモバイル端末を使って作業を行うことができるようにするのがCouchbaseのモバイルソリューションです。
It’s very irritating if I have to depend on connectivity to do work.
With Couchbase Mobile Solution, you have no stress to work at anytime, anywhere, without being aware that you are online or offline.
それでは、Couchbaseのモバイルソリューションがどのように機能するか、どのような場面で使用することができるかについて技術的な観点(かんてん)からもう少しお話したいと思います。
Couchbase Mobile is the answer to this annoying problem, and we think you’ll love it as much as we do.
So, what it does it do, and how does it work?
CouchbaseのモバイルソリューションはCouchbase Lite, Sync Gateway, Couchbase Serverの3つの製品から成り立つ1つのソリューションです。
CBLはモバイル端末で動作するローカルのNoSQLデータベース、Sync Gatewayはモバイル端末とサーバ間の同期、Couchbase Serverはドキュメント指向のNoSQLデータベースです。
今回は世界で初のモバイル端末上で稼動してローカルにデータを保存するNoSQLデータベースCouchbase Liteと、ローカルデータベースとサーバの間で同期の役割をするSync Gatewayについて解説します。
This workshop introduces the world's first embedded NoSQL solution: Couchbase Mobile. The complete Couchbase stack consists of three parts: Couchbase Lite, Sync Gateway, and Couchase Server.
In this workshop, we will introduce Couchbase Lite (an embedded NoSQL DB) which lives on mobile devices and Sync Gateway which functions between Couchbase Lite and the cloud NoSQL database, Couchbase Server.
We have Couchbase Lite, which runs on the device
And we have Sync Gateway, which stands on the border between your private cloud and the public cloud.
Couchbase Liteは世界で初めてのNoSQLモバイルデータベースです。別プロセスではなくアプリに組み込まれるためフットプリントが小さいのが特徴です。
そして機能は主に4つ分かれています。
ドキュメント指向データベース
MapReduceクエリのエンジン
様々な変更通知
マルチマスター同期
それでは各項目について詳細をお話したいと思います。
Couchbase Lite is the world first NoSQL mobile database which means it runs in process with your application, and it has a very small footprint.
We have four major feature areas:
1. It is a document oriented database
2. It provides a Map Reduce query engine
3. It provides a suite of event notifications
4. It provides sync (multi master replication)
まず始めに機能の1つ、ドキュメント指向データベースを紹介したいと思います。
Couchbase Liteは世界で初のドキュメント指向のモバイルデータベースで、KV構造(こうぞう)、スキーマレス、開発スピードや動作の高速化などの特徴が挙げられます。
リレーショナル・データベースの世界ではテーブルとそのテーブル内の関係を定義するかと思いますが、アプリのオブジェクト・モデルのためにデータを取得する際にO/Rマッピングを行う必要がありますので、コードが増えてしまいます。
反対(はんたい)に、ドキュメント指向データベースはアプリと同じデータ構成を使います。具体的にはキー・バリューのコレクションを指します。つまりiOSだとNSDictionary、JavaだとMapで.NETだとDictionaryです。
キー・バリューコレクションである上にキー・バリュー・ペアの変更をモニタリングするためにバージョン履歴をドキュメント毎に書き込みます。
O/Rマッピングなど関係なくなります。キー・バリュー・ペアの使い方さえ分かれば問題ありません。そして、再帰的にオブジェクトを突っ込みますのでJOINなどの心配はする必要がなくなります。メモリに必要な情報を直接入れることができますので、スキーマの整理や正規化と非正規化がなく、アプリのロジックがより簡単になります。
それによって開発も動作も早くなります。Couchbase LiteはオブジェクトモデルをJSONで保存しています。開発者はJSONに使い慣れているので違和感無く始められるかと思います。更に、データベースはJSON対応してますので、開発スピードも、動作もはるかに高速になります。
Let’s talk about Document Oriented Database.
If we are coming from a relational model, we are familiar with modeling our data in third model form, where we have a number of tables and we define all of these relationships between the tables. When we need to retrieve the data from these normalized database schemas into our object model in-memory, we go through some object relational mapping (it’s a lot of cruft to keep up with).
In contrast, the document oriented database, uses the data structure we are already using in our applications. More specifically, it is a collection of key-value pairs. In iOS, you’re looking at an NSDictionary, in Java you are looking at a Map, and in .NET you’re looking at a Dictionary.
In addition to being a key-value pair collection, we also add in to documents a version history, so we can track the changes in that key-value pair all the time.
We don’t have to deal with normalizing data anymore. We only need to know how to use a key-value pair. Because we insert nested object graphs within that key-value pair, we don’t need to worry about joins and things like that. What ever object graphs we need to have in-memory, we just store in the key-value pair collection. This vastly simplifies how we build our applications because we no longer have to deal with the book keeping aspects of schemas and the problems of going between normalized data and de-nomalized data.
That lets us code fast and run fast. Internally on disk, we use JSON serialization to represent the object model. We are using whatever basic skills you are already familiar with in dealing with JSON data, but we’ve taught our database how to deal with JSON data so it’s fast.
次に2つ目の機能であるMapReduceインデックスについて説明します。
まず、MapReduceインデックスはネイティブ言語で開発することが可能です。つまりMapRecuceのインデックスを作るのに新たに他の言語を習得する必要がないため、開発を非常に効率的に行うことができます。
また、MapReduceインデックスによってドキュメントの素早いクエリを行うことができます。結果は保存されますのでクエリは超高速です。
最後に、このMapReduceインデックスを使うとデバッグが非常に効率的にできるようになります。別の組み込みSQL言語を頼りにすると、遅くなったり違う結果が出てしまっても直接操作できるデバッグ方法がありません。成功するのに試行錯誤(しこうさくご)するしかないのがとても不便です。MapReduceクエリエンジンを使うとツールと同じデバッガーを使うことができます。そしてどこでおかしくなっているか知りたい場合はブレークポイントを設定するだけでデバッグを行えるので非常に便利です。
MapReduce Indexes: provide us the mechanisms for doing very fast queries against our documents. This lets us build our indexes in our native language. When we’re dealing with two languages, we have to resort to an embedded string-based language for SQL that works completely different, and we have no direct way of being able to debug why an index is slow or why it’s not returning the correct results. We have to do a lot of trial and error to get it right.
By providing a MapReduce query engine, we’re able to use the same debugger, the same tools we are already using.
The results are persisted, so your queries are lightening fast.
If we’re trying to figure out where things are going on, all we have to do is set up breakpoint.
3つ目のCouchbase Liteの特徴は変更通知です。
Couchbase Liteのオブジェクトにはそれぞれの開発言語の標準のイベントシステムによって変更通知の登録、監視を行うことができます。
どのような登録ができるかというと、データベース、クエリ、セッション、ドキュメントなどになります。この変更通知を使って、データに対してどこで何が変わったかという情報がすぐ手に入ります。
これもソースコードを減らすことに繋がります。ライブクエリを作成し、ロジックを設定して終わりなのでとても簡単です。
Change Notifications: Objects in Couchbase lite, let you listen for changes/ observe for changes, using the standard or native change/ event notification system of your language of choice.
Multiple scopes for change notifications – we can listen for them at the database level, individual query level, replication/ sync session level, even down to specific documents.
It cuts down significantly on the amount of cruft code we have to write. All we do is create our live query and then provide the functional call back using the language specific notification system to drive UI updates. Once we’ve taught our application how to deal with changes in data, we can set it and walk away.
4つ目の特徴はマルチマスター同期です。
マルチマスターというのはマスター・マスターと違って複数のエンドポイントに同期ができます。Couchbase Liteにはマルチマスター同期が機能として入っています。
同期は継続的(つまり、データができるだけ早く変更されてから同期されます)かアドホック(つまり同期が終わった後にもう一回同期したい場合は手動的に行う必要がある)という2つの種類があります。同期は単方向(たんほうこう)、双方向(そうほうこう)のどちらの方向もできます。
継続的かアッドホックという選択があるメリットは電池の省エネができることです。モバイルデバイスの電池を一番消費するのは電波接続です。電波接続を少なく使うのがベストです。実は継続的に同期する必要がないアプリが多いです。たくさんのアプリは起動時に製品カタログを更新したり、終了時にログやアナリティクスを送信したりするような処理だけします。ユーザーか購入やリクエストをする際にアドホックの同期を行うのは可能です。そういったデータに関しましては継続的な同期の必要はなさそうです。自分のアプリのデータとその処理を考慮した上に決める方がよいでしょう。そして、前に紹介した変更通知と同様、情報が変わるとイベントが発生します。さらに、Gitなどのバージョン管理と同じMVCCを使っています。従って、競合が入って来ると自動的に解決するかアプリのロジックによって解決することができます。
Sync: a very simple mechanism in Couchbase Lite. Full multi-master replication (not master-master because you are not limited to only one end point, you can sync with N number of end points)
Sessions can be run either continuously (minimum latency in data changes between two systems) or ad-hoc, as soon as the sync session is done, then that’s it. Any further updates, you will have to run another sync session. Sync sessions can be done in either direction.
The nice thing about being able to had the choice between continuous and ad-hoc, we can be good about our end users battery life. The biggest drain on our mobile devices, our batteries, is the radio. You want to minimize the amount of radio usage our app requires. You want to make sure we are using the minimum for the use case that we have. Many applications don’t have a lot or any data that needs to be synced in real times. Many apps can pull at app start up to refresh a product catalogue (retail) or just do a one off push when they are closing, to push off logging or analytical data. As a user completes a purchase or individual request, there can be a one-off push sync. We don’t need to be in continuous push or pull mode for those types of data. You have to look at your application and the kind of data (speed and flows) you have and we can handle it responsibly with Couchbase lite.
We get our change in notifications, and we also get the ability through that mechanism to do conflict detection. Each document will provide a list of conflicting revisions, if there are any. Couchbase lite implements the same MVCC algorithm that Git uses and Mercurial, and most other distributed versioning systems use. If you’re familiar with how to use those tools, then you will be very comfortable with Couchbase lite. In Git for example, if you’ve got a branch, we call that a document, if you have a commit, we call that a revision. If you have two commits in conflict, many times they can be auto-merged, and in the cases you can’t, you simply make a merge-commit, just like you would in Git, except we would have a merge revision in that case. It’s very simple and easy to use.
こちらはCouchbaseがサポートしている言語とプラットフォームです。iOS (Swift / Objective-C両方)、Android、.NETとJavaの上にPhoneGapやXamarinやTitaniumの様なマルチプラットフォーム環境もサポートしております。
入手するにはCocoapods, Maven Central, Nuget, 並びにGitHubからソースもダウンロードすることが出来ます。それらによって開発者のプロジェクトに追加することを簡単にいたします。
GEでは既存のシステムからこのCouchbaseモバイルへの移行へ決断するのに1日、検証に5日、データ以降に30日、その他機能面などの調整や移行などで計90日でプロジェクトを完成させたそうです。Predixは冒頭(ぼうとう)で紹介したように重工業向けのかなり大規模(だいきぼ)かつ様々な分野を対象にしたプラットフォームであるのに関わらず、これほど早く開発ができたのはまさにNoSQLの恩恵を受けたからと言えるかと思います。
These are the platforms and languages and environments we support. Any modern and popular operating system we provide support for, for Couchbase lite. We provide native implementations for iOS and also, we support Swift, Java, and .NET as well. We also support multi-platform programming environments like Phonegap, Xamarin, and Appcellerator’s Titanium.
You can get your hands on Couchbase Lite by Cocoapods, Maven Central, Nuget if you’re a .NET developer, or you can get the source from Github. We make it super easy to add to your project and to get started with.
続いて、Sync Gatewayについて話します。この図はSync Gateway内部の構造を表しています。
Sync GatewayはCouchbase Lite (ローカルデータベース)とCouchbase Server (NoSQLデータベース)の間で機能するアプリケーションです。
つまり、モバイルアプリとクラウドをつなぐ役割を担(にな)います。普通のウェブアプリケーションのように認証と権限付与を行うだけでなく、独自的にデータの扱いも行います。
様々なデバイスからデータを収集したり、許可されたユーザだけに書込み権限を与えたり、閲覧権利のないユーザのデバイスと同期しないなど、様々な定義の方法があります。
またTBもの大きなデータをモバイル端末に保存できない、またはしたくない場合、一部のデータだけ端末にもち、残りのデータをサーバから同期しない方法もSync Gatewayで設定することができます。
Let’s talk about Sync Gateway. Sync Gateway handles the boundary between your private data center and your public cloud. When I say private data center, that can still be in a public cloud like EC2 or Azure where you’ve got a number of VMs running. It handles the same cross cutting concerns from your application that you would have in any web-based application: things like Authentication, Authorization, and unique to Sync Gateway: it provides a method of data orchestration.
We often have all these streams of documents coming up from different devices, and we want to do things like ensure that writes are only allowed to documents where users have appropriate authorization and make sure that, if someone shouldn’t be able to see a document, that it doesn’t get replicated down to their device.
We also need to define relevancy, because we can’t possibly fit the entire application database of however many terabytes onto an individual phone. We need to only sync the information that user cares about, and we need a way to programmatically define what that user cares about. And that’s another thing that Sync Gateway does for you.
更に、Sync Gatewayはアプリのデータをクラウド、つまりCouchbase Serverに送って保存するという役割も行っています。デバイスがSync Gatewayに同期していると同時にSync GatewayがCouchbase Serverに書き込んでいます。
Sync gateway also handles the permanent persistence of your applications data in your Couchbase Server cluster that lives in your private data center. So as your device is syncing with sync gateway and pushing your data up, sync gateway is also writing that data into the permanent data store, backed by our highly scalable Couchbase Server technology.