SlideShare uma empresa Scribd logo
1 de 14
erLocator
erLocator
Overview - Objective

  Make Erlang more accessible and less daunting.

  The demonstration application will:
      • Leverage a NoSQL backend
      • Use Natively Implemented Functions
      • Exhibit eDoc and Rebar
      • and provide an interesting feature that might actually be useful.

  The application is hosted on GitHub and licensed MIT.


  Demo:             erlocator.org

  Code:             github.com/erlocator/erlocator.git
erLocator
Overview - Concept

  Track user locations such that nearby users can be found efficiently.

  • Do not perform radius or distance calculations on each data element.
  • Do not perform range filtering by latitude and longitude.

  • Store user entries by region.
  • Return users within the same and adjacent regions.

  Where the user U is in the center region,
  return the records of users in the 3 x 3
  grid of regions surrounding that user.

  In the diagram, users represented as red
  dots are returned, while users in blue
  are outside the range.

  This is exposed as a web api.

  There is no security – deploy wisely.
erLocator
Overview – Front End

  • The front end simply demonstrates the back end.
  • Components
     • Twitter bootstrap: reasonable design out of the box.
     • Google Maps API: familiar presentation of geolocation data.
     • Facebook javascript API: expose user identity with location.
  • Licensed: MIT
  • View it on the web
     • http://erlocator.org
erLocator
Overview – Back End

 • A very simple erlang application.
 • Core Technology
    • Store users in small regions based on geolocation.
    • Return a set of those regions so that users can find others nearby.
 • Demonstrates
    • Geonum for numerical hashes that support bitwise masking.
    • Natively Implemented Functions in C for performance.
    • Redis to store in-memory data structures with Redo.
    • Mochiweb to expose a web api.
    • eDoc to document code.
    • Rebar for builds.
 • Licensed: MIT
 • Get it on Github
    • erlocator/erlocator
    • erlocator/geonum
erLocator
Backend - GeoNum

 We group user locations within ranges by hashing the latitude and longitude
 using a numeric version of GeoHash called GeoNum. The hashing algorithm
 simply divides latitude and longitude in half repetitively, assigning 1 for larger
 and 0 for smaller values in the initial data. This process continues until the
 desired precision has been encoded, and the bits of latitude and longitude are
 interleaved in a single integer padded with 1 in the most significant bit.

 We calculate a GeoNum with 25 bits of overall precision. This same hash will
 be returned for all locations within that region.

          LAT 37.7891726
                                               GeoNum 43721694
          LNG -122.4102559

                                   GeoNum
                    10100110110010001111011110
erLocator
Backend – GeoNum NIF – Erlang

 Small routines that are compute intensive can be written in C and used in
 Erlang applications as Natively Implemented Functions. The NIF in this
 application is here ( GitHub: erlocator/geonum )

 To use C functions, init() loads the shared library on module load:
  erlang:load_nif(SoName, 0)

 Then we call appropriately named Erlang wrappers. In this example,
 the NIF is named geonum, and the function is named encode:

  %% @doc Encode latitude and longitude into a geonum
 -spec encode(float(), float(), pos_integer()) -> binary().
 encode(_Latitude, _Longitude, _Precision) ->
   exit(geonum_nif_not_loaded).

 The example wraps the NIF in Erlang and exports its functions:

 -module(geonum).

 -export([
     encode/3,
 ]).                                             Documentation: http://www.erlang.org/doc/tutorial/nif.html
erLocator
Backend – GeoNum NIF - C

 The C includes the Erlang NIF header, exports the functions with
 ERL_NIF_INIT, and prepares the return values to be understood
 by Erlang.

 #include "erl_nif_compat.h”
 …

 /**
  * Erlang Wrapper for geonum_encode
  */
 ERL_NIF_TERM
 erl_geonum_encode(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
 {
     … function code here …
     return make_ok(env, enif_make_int64(env, bin_geonum[0]));
 }

 …

 static ErlNifFunc nif_functions[] = {
    {"encode", 3, erl_geonum_encode}
 };

 ERL_NIF_INIT(geonum, nif_functions, &on_load, &on_reload, &on_upgrade, NULL);


                                            Documentation: http://www.erlang.org/doc/tutorial/nif.html
erLocator
Back End – Redis

  Redis (REmote DIctionary Service)
      • Stores and serves foundational data structures.
      • Provides a sort of shared memory for many systems.
      • Very fast.
      • Limited horizontal scaling capabilities at present.
      • Presently single-threaded.
      • See: http://redis.io/topics/benchmarks
      • Configurable to store only in RAM.
      • BSD License
      • http://redis.io/
      • Command reference: http://redis.io/commands

  Optimal Redis Use Case
      • Small data.
          • Full data set must fit in physical RAM.
      • Frequent reads and writes.
      • Transient.
erLocator
Back End – Redis Keys and Redo

  • Redis key structure
     • geonum:{numeric hash}
          • SET of user IDs within the specified region.
     • geonum_user:{facebook id}
          • STRING containing user information.
              • Name
              • Picture
              • Profile link
              • Full geolocation information
              • For convenience, this data is stored as an
                 Erlang term representing pre-parsed JSON.
     • geonum_expire
          • ZSET (sorted set)
              • User IDs
              • Scored by future expiration time
  • Redo
     • Very, very simple implementation of Redis Erlang client.
     • One api function, takes a raw Redis command: redo:cmd
     • https://github.com/JacobVorreuter/redo
     • MIT License (apparently).
erLocator
Backend - Mochiweb

 • Erlang library for building lightweight http servers.
 • https://github.com/mochi/mochiweb

 URL Routing

 loop(Req, DocRoot, AppParams) ->
    "/" ++ Path = Req:get(path),
    case Req:get(method) of
       Method when Method =:= 'GET'; Method =:= 'HEAD' ->
          Params = Req:parse_qs(),
          case Path of
            "" ->
               Req:serve_file("html/hello.html", DocRoot)
          end;

     'POST' ->
        Params = Req:parse_post(),
        case Path of
          ”url" ->
             code;
          _ ->
             Req:not_found()
        end;
     _ ->
        Req:respond({501, [], []})
   end.
erLocator
Backend - Rebar

  •     Widely accepted Erlang build tool.
  •     Apache license.
  •     GitHub: basho/rebar ( https://github.com/rebar/rebar/wiki/rebar )
  •     Call rebar when running make.
  •     Makefile
      REBAR=rebar

      DEPS_EBIN = `find . -name ebin -type d`

      all:
                 @$(REBAR) get-deps
                 for a in deps/*; do cd $$a; make; cd -; done
                 @$(REBAR) compile
                 @$(REBAR) doc
      clean:
                 for a in deps/*; do cd $$a; make clean; cd -; done
                 @$(REBAR) clean


  • Rebar.config
      {deps, [
                 {geonum, "0.1.0", {git, "git://github.com/erlocator/geonum.git"}}
      ]}.
      %%{lib_dirs,["deps"]}.
      %%{erl_opts,[]}.
erLocator
Backend - eDoc

  • eDoc is the standard for documenting Erlang applications.
  • http://www.erlang.org/doc/apps/edoc/chapter.html
  • Generate documentation: rebar doc
  • Overview: doc/overview.edoc
      • An overview of the application.
      • Top page of generated documentation.
  • File headers:
      %% @author Boris Okner <boris.okner@gmail.com>
      %% @author Josh Murphy <jmurphy@lostbitz.com>
      %% @author Christian Gribneau <christian@gribneau.net>
      %% @copyright 2013
      %% @doc Web server for geofilter.

  • Function descriptions:
      %% @doc Stop the geofilter webserver.
      stop() ->
         mochiweb_http:stop(?MODULE).
erLocator
Conclusion




             Questions?

Mais conteúdo relacionado

Mais procurados

DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthFelipe Prado
 
Erlang
ErlangErlang
ErlangESUG
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with ErlangMaxim Kharchenko
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Adam Tomat
 
Practical Kerberos with Apache HBase
Practical Kerberos with Apache HBasePractical Kerberos with Apache HBase
Practical Kerberos with Apache HBaseJosh Elser
 
Binding Objective-C Libraries, Miguel de Icaza
Binding Objective-C Libraries, Miguel de IcazaBinding Objective-C Libraries, Miguel de Icaza
Binding Objective-C Libraries, Miguel de IcazaXamarin
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM Mark Rees
 
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例National Cheng Kung University
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in ScalaKnoldus Inc.
 
How to collect Big Data into Hadoop
How to collect Big Data into HadoopHow to collect Big Data into Hadoop
How to collect Big Data into HadoopSadayuki Furuhashi
 
Enhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through OntologyEnhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through OntologyChunhua Liao
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with ErlangMaxim Kharchenko
 
Cockatrice: A Hardware Design Environment with Elixir
Cockatrice: A Hardware Design Environment with ElixirCockatrice: A Hardware Design Environment with Elixir
Cockatrice: A Hardware Design Environment with ElixirHideki Takase
 
Hadoop MapReduce Introduction and Deep Insight
Hadoop MapReduce Introduction and Deep InsightHadoop MapReduce Introduction and Deep Insight
Hadoop MapReduce Introduction and Deep InsightHanborq Inc.
 

Mais procurados (18)

DEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depthDEF CON 27 - JEFF DILEO - evil e bpf in depth
DEF CON 27 - JEFF DILEO - evil e bpf in depth
 
Hadoop on osx
Hadoop on osxHadoop on osx
Hadoop on osx
 
Erlang
ErlangErlang
Erlang
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
 
Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018Supercharging WordPress Development in 2018
Supercharging WordPress Development in 2018
 
Next Stop, Android
Next Stop, AndroidNext Stop, Android
Next Stop, Android
 
Practical Kerberos with Apache HBase
Practical Kerberos with Apache HBasePractical Kerberos with Apache HBase
Practical Kerberos with Apache HBase
 
Fluentd meetup at Slideshare
Fluentd meetup at SlideshareFluentd meetup at Slideshare
Fluentd meetup at Slideshare
 
Binding Objective-C Libraries, Miguel de Icaza
Binding Objective-C Libraries, Miguel de IcazaBinding Objective-C Libraries, Miguel de Icaza
Binding Objective-C Libraries, Miguel de Icaza
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM
 
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
 
Logging with Logback in Scala
Logging with Logback in ScalaLogging with Logback in Scala
Logging with Logback in Scala
 
How to collect Big Data into Hadoop
How to collect Big Data into HadoopHow to collect Big Data into Hadoop
How to collect Big Data into Hadoop
 
Enhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through OntologyEnhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through Ontology
 
0.5mln packets per second with Erlang
0.5mln packets per second with Erlang0.5mln packets per second with Erlang
0.5mln packets per second with Erlang
 
Cockatrice: A Hardware Design Environment with Elixir
Cockatrice: A Hardware Design Environment with ElixirCockatrice: A Hardware Design Environment with Elixir
Cockatrice: A Hardware Design Environment with Elixir
 
Hadoop MapReduce Introduction and Deep Insight
Hadoop MapReduce Introduction and Deep InsightHadoop MapReduce Introduction and Deep Insight
Hadoop MapReduce Introduction and Deep Insight
 
General Purpose GPU Computing
General Purpose GPU ComputingGeneral Purpose GPU Computing
General Purpose GPU Computing
 

Destaque

Futbol mas avansada diapositiva mas avansada
Futbol mas avansada diapositiva mas avansadaFutbol mas avansada diapositiva mas avansada
Futbol mas avansada diapositiva mas avansadalalin8
 
Reporte Diario Bursátil del 17 de Diciembre del 2015
Reporte Diario Bursátil del 17 de Diciembre del 2015Reporte Diario Bursátil del 17 de Diciembre del 2015
Reporte Diario Bursátil del 17 de Diciembre del 2015Grupo Coril
 
Evaluating Policy Statements
Evaluating Policy StatementsEvaluating Policy Statements
Evaluating Policy StatementsMelodee Peters
 
Presentacion arken internacional (1)
Presentacion arken internacional (1)Presentacion arken internacional (1)
Presentacion arken internacional (1)arken210
 
A MéRnöKké VáLáS RöGöS úTja
A MéRnöKké VáLáS RöGöS úTjaA MéRnöKké VáLáS RöGöS úTja
A MéRnöKké VáLáS RöGöS úTjavasil.iliev
 
Chuong1 tong quantcdn
Chuong1 tong quantcdnChuong1 tong quantcdn
Chuong1 tong quantcdnNgo Van Toan
 
Client Training: How to use glassdoor to prep your Q1 hiring
Client Training: How to use glassdoor to prep your Q1 hiringClient Training: How to use glassdoor to prep your Q1 hiring
Client Training: How to use glassdoor to prep your Q1 hiringGlassdoor
 

Destaque (15)

"Как Нами Манипулируют"
"Как Нами Манипулируют""Как Нами Манипулируют"
"Как Нами Манипулируют"
 
Futbol mas avansada diapositiva mas avansada
Futbol mas avansada diapositiva mas avansadaFutbol mas avansada diapositiva mas avansada
Futbol mas avansada diapositiva mas avansada
 
Relacion de ponentes aceptadas
Relacion de ponentes aceptadasRelacion de ponentes aceptadas
Relacion de ponentes aceptadas
 
Reporte Diario Bursátil del 17 de Diciembre del 2015
Reporte Diario Bursátil del 17 de Diciembre del 2015Reporte Diario Bursátil del 17 de Diciembre del 2015
Reporte Diario Bursátil del 17 de Diciembre del 2015
 
Evaluating Policy Statements
Evaluating Policy StatementsEvaluating Policy Statements
Evaluating Policy Statements
 
Presentacion arken internacional (1)
Presentacion arken internacional (1)Presentacion arken internacional (1)
Presentacion arken internacional (1)
 
Orden de conferencias magistrales (1)
Orden de conferencias magistrales (1)Orden de conferencias magistrales (1)
Orden de conferencias magistrales (1)
 
Ponencias VII Simposio de Historia
Ponencias VII Simposio de HistoriaPonencias VII Simposio de Historia
Ponencias VII Simposio de Historia
 
Нейминг Интернет-портала
Нейминг Интернет-порталаНейминг Интернет-портала
Нейминг Интернет-портала
 
A MéRnöKké VáLáS RöGöS úTja
A MéRnöKké VáLáS RöGöS úTjaA MéRnöKké VáLáS RöGöS úTja
A MéRnöKké VáLáS RöGöS úTja
 
Chuong1 tong quantcdn
Chuong1 tong quantcdnChuong1 tong quantcdn
Chuong1 tong quantcdn
 
Quezambra, T
Quezambra, TQuezambra, T
Quezambra, T
 
Client Training: How to use glassdoor to prep your Q1 hiring
Client Training: How to use glassdoor to prep your Q1 hiringClient Training: How to use glassdoor to prep your Q1 hiring
Client Training: How to use glassdoor to prep your Q1 hiring
 
Patria nueva
Patria nuevaPatria nueva
Patria nueva
 
Expedición de Diego de Almagro
Expedición de Diego de AlmagroExpedición de Diego de Almagro
Expedición de Diego de Almagro
 

Semelhante a Find nearby users efficiently with erLocator

Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and ExecutionChong-Kuan Chen
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architectureRomain Rochegude
 
DConf2015 - Using D for Development of Large Scale Primary Storage
DConf2015 - Using D for Development  of Large Scale Primary StorageDConf2015 - Using D for Development  of Large Scale Primary Storage
DConf2015 - Using D for Development of Large Scale Primary StorageLiran Zvibel
 
Cloud Foundry V2 | Intermediate Deep Dive
Cloud Foundry V2 | Intermediate Deep DiveCloud Foundry V2 | Intermediate Deep Dive
Cloud Foundry V2 | Intermediate Deep DiveKazuto Kusama
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxMichael Hackstein
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)goccy
 
Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overviewjessesanford
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.pptWalaSidhom1
 
Saving Money with Open Source GIS
Saving Money with Open Source GISSaving Money with Open Source GIS
Saving Money with Open Source GISbryanluman
 
Centralized Application Configuration with Spring and Apache Zookeeper
Centralized Application Configuration with Spring and Apache ZookeeperCentralized Application Configuration with Spring and Apache Zookeeper
Centralized Application Configuration with Spring and Apache ZookeeperRyan Gardner
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsasync_io
 
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...Sencha
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfssuser705051
 
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd についてKubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd についてLINE Corporation
 
LocationTech Projects
LocationTech ProjectsLocationTech Projects
LocationTech ProjectsJody Garnett
 
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESSMERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESSannalakshmi35
 
Fast Data Analytics with Spark and Python
Fast Data Analytics with Spark and PythonFast Data Analytics with Spark and Python
Fast Data Analytics with Spark and PythonBenjamin Bengfort
 

Semelhante a Find nearby users efficiently with erLocator (20)

Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
 
iOS Swift application architecture
iOS Swift application architectureiOS Swift application architecture
iOS Swift application architecture
 
DConf2015 - Using D for Development of Large Scale Primary Storage
DConf2015 - Using D for Development  of Large Scale Primary StorageDConf2015 - Using D for Development  of Large Scale Primary Storage
DConf2015 - Using D for Development of Large Scale Primary Storage
 
Cloud Foundry V2 | Intermediate Deep Dive
Cloud Foundry V2 | Intermediate Deep DiveCloud Foundry V2 | Intermediate Deep Dive
Cloud Foundry V2 | Intermediate Deep Dive
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
 
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)これからのPerlプロダクトのかたち(YAPC::Asia 2013)
これからのPerlプロダクトのかたち(YAPC::Asia 2013)
 
Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
 
nodejs_at_a_glance.ppt
nodejs_at_a_glance.pptnodejs_at_a_glance.ppt
nodejs_at_a_glance.ppt
 
Saving Money with Open Source GIS
Saving Money with Open Source GISSaving Money with Open Source GIS
Saving Money with Open Source GIS
 
Centralized Application Configuration with Spring and Apache Zookeeper
Centralized Application Configuration with Spring and Apache ZookeeperCentralized Application Configuration with Spring and Apache Zookeeper
Centralized Application Configuration with Spring and Apache Zookeeper
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
SenchaCon 2016: Advanced Techniques for Buidling Ext JS Apps with Electron - ...
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
 
Terraform-2.pdf
Terraform-2.pdfTerraform-2.pdf
Terraform-2.pdf
 
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd についてKubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
Kubernetes上で動作する機械学習モジュールの配信&管理基盤Rekcurd について
 
HDF-EOS Java Application Programming Interfaces
HDF-EOS Java Application Programming InterfacesHDF-EOS Java Application Programming Interfaces
HDF-EOS Java Application Programming Interfaces
 
LocationTech Projects
LocationTech ProjectsLocationTech Projects
LocationTech Projects
 
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESSMERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
MERN SRTACK WEB DEVELOPMENT NODE JS EXPRESS
 
Fast Data Analytics with Spark and Python
Fast Data Analytics with Spark and PythonFast Data Analytics with Spark and Python
Fast Data Analytics with Spark and Python
 

Find nearby users efficiently with erLocator

  • 2. erLocator Overview - Objective Make Erlang more accessible and less daunting. The demonstration application will: • Leverage a NoSQL backend • Use Natively Implemented Functions • Exhibit eDoc and Rebar • and provide an interesting feature that might actually be useful. The application is hosted on GitHub and licensed MIT. Demo: erlocator.org Code: github.com/erlocator/erlocator.git
  • 3. erLocator Overview - Concept Track user locations such that nearby users can be found efficiently. • Do not perform radius or distance calculations on each data element. • Do not perform range filtering by latitude and longitude. • Store user entries by region. • Return users within the same and adjacent regions. Where the user U is in the center region, return the records of users in the 3 x 3 grid of regions surrounding that user. In the diagram, users represented as red dots are returned, while users in blue are outside the range. This is exposed as a web api. There is no security – deploy wisely.
  • 4. erLocator Overview – Front End • The front end simply demonstrates the back end. • Components • Twitter bootstrap: reasonable design out of the box. • Google Maps API: familiar presentation of geolocation data. • Facebook javascript API: expose user identity with location. • Licensed: MIT • View it on the web • http://erlocator.org
  • 5. erLocator Overview – Back End • A very simple erlang application. • Core Technology • Store users in small regions based on geolocation. • Return a set of those regions so that users can find others nearby. • Demonstrates • Geonum for numerical hashes that support bitwise masking. • Natively Implemented Functions in C for performance. • Redis to store in-memory data structures with Redo. • Mochiweb to expose a web api. • eDoc to document code. • Rebar for builds. • Licensed: MIT • Get it on Github • erlocator/erlocator • erlocator/geonum
  • 6. erLocator Backend - GeoNum We group user locations within ranges by hashing the latitude and longitude using a numeric version of GeoHash called GeoNum. The hashing algorithm simply divides latitude and longitude in half repetitively, assigning 1 for larger and 0 for smaller values in the initial data. This process continues until the desired precision has been encoded, and the bits of latitude and longitude are interleaved in a single integer padded with 1 in the most significant bit. We calculate a GeoNum with 25 bits of overall precision. This same hash will be returned for all locations within that region. LAT 37.7891726  GeoNum 43721694 LNG -122.4102559 GeoNum 10100110110010001111011110
  • 7. erLocator Backend – GeoNum NIF – Erlang Small routines that are compute intensive can be written in C and used in Erlang applications as Natively Implemented Functions. The NIF in this application is here ( GitHub: erlocator/geonum ) To use C functions, init() loads the shared library on module load: erlang:load_nif(SoName, 0) Then we call appropriately named Erlang wrappers. In this example, the NIF is named geonum, and the function is named encode: %% @doc Encode latitude and longitude into a geonum -spec encode(float(), float(), pos_integer()) -> binary(). encode(_Latitude, _Longitude, _Precision) -> exit(geonum_nif_not_loaded). The example wraps the NIF in Erlang and exports its functions: -module(geonum). -export([ encode/3, ]). Documentation: http://www.erlang.org/doc/tutorial/nif.html
  • 8. erLocator Backend – GeoNum NIF - C The C includes the Erlang NIF header, exports the functions with ERL_NIF_INIT, and prepares the return values to be understood by Erlang. #include "erl_nif_compat.h” … /** * Erlang Wrapper for geonum_encode */ ERL_NIF_TERM erl_geonum_encode(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { … function code here … return make_ok(env, enif_make_int64(env, bin_geonum[0])); } … static ErlNifFunc nif_functions[] = { {"encode", 3, erl_geonum_encode} }; ERL_NIF_INIT(geonum, nif_functions, &on_load, &on_reload, &on_upgrade, NULL); Documentation: http://www.erlang.org/doc/tutorial/nif.html
  • 9. erLocator Back End – Redis Redis (REmote DIctionary Service) • Stores and serves foundational data structures. • Provides a sort of shared memory for many systems. • Very fast. • Limited horizontal scaling capabilities at present. • Presently single-threaded. • See: http://redis.io/topics/benchmarks • Configurable to store only in RAM. • BSD License • http://redis.io/ • Command reference: http://redis.io/commands Optimal Redis Use Case • Small data. • Full data set must fit in physical RAM. • Frequent reads and writes. • Transient.
  • 10. erLocator Back End – Redis Keys and Redo • Redis key structure • geonum:{numeric hash} • SET of user IDs within the specified region. • geonum_user:{facebook id} • STRING containing user information. • Name • Picture • Profile link • Full geolocation information • For convenience, this data is stored as an Erlang term representing pre-parsed JSON. • geonum_expire • ZSET (sorted set) • User IDs • Scored by future expiration time • Redo • Very, very simple implementation of Redis Erlang client. • One api function, takes a raw Redis command: redo:cmd • https://github.com/JacobVorreuter/redo • MIT License (apparently).
  • 11. erLocator Backend - Mochiweb • Erlang library for building lightweight http servers. • https://github.com/mochi/mochiweb URL Routing loop(Req, DocRoot, AppParams) -> "/" ++ Path = Req:get(path), case Req:get(method) of Method when Method =:= 'GET'; Method =:= 'HEAD' -> Params = Req:parse_qs(), case Path of "" -> Req:serve_file("html/hello.html", DocRoot) end; 'POST' -> Params = Req:parse_post(), case Path of ”url" -> code; _ -> Req:not_found() end; _ -> Req:respond({501, [], []}) end.
  • 12. erLocator Backend - Rebar • Widely accepted Erlang build tool. • Apache license. • GitHub: basho/rebar ( https://github.com/rebar/rebar/wiki/rebar ) • Call rebar when running make. • Makefile REBAR=rebar DEPS_EBIN = `find . -name ebin -type d` all: @$(REBAR) get-deps for a in deps/*; do cd $$a; make; cd -; done @$(REBAR) compile @$(REBAR) doc clean: for a in deps/*; do cd $$a; make clean; cd -; done @$(REBAR) clean • Rebar.config {deps, [ {geonum, "0.1.0", {git, "git://github.com/erlocator/geonum.git"}} ]}. %%{lib_dirs,["deps"]}. %%{erl_opts,[]}.
  • 13. erLocator Backend - eDoc • eDoc is the standard for documenting Erlang applications. • http://www.erlang.org/doc/apps/edoc/chapter.html • Generate documentation: rebar doc • Overview: doc/overview.edoc • An overview of the application. • Top page of generated documentation. • File headers: %% @author Boris Okner <boris.okner@gmail.com> %% @author Josh Murphy <jmurphy@lostbitz.com> %% @author Christian Gribneau <christian@gribneau.net> %% @copyright 2013 %% @doc Web server for geofilter. • Function descriptions: %% @doc Stop the geofilter webserver. stop() -> mochiweb_http:stop(?MODULE).
  • 14. erLocator Conclusion Questions?