N2O Most Powerful Erlang Web Framework @5HT



Similar documents
Clojure Web Development

Modern Web Development From Angle Brackets to Web Sockets

Drupal CMS for marketing sites

This course provides students with the knowledge and skills to develop ASP.NET MVC 4 web applications.

CSE 373: Data Structure & Algorithms Lecture 25: Programming Languages. Nicki Dell Spring 2014

FormAPI, AJAX and Node.js

Traitware Authentication Service Integration Document

Clojure Web Development

What is a stack? Do I need to know?

10CS73:Web Programming

Tech Radar - May 2015

The Decaffeinated Robot

IBM Digital Experience. Using Modern Web Development Tools and Technology with IBM Digital Experience

Fachgebiet Technische Informatik, Joachim Zumbrägel

General Introduction

A CMS framework in Erlang. Marc Worrell WhatWebWhat

Client Side Binding of Dynamic Drop Downs

Modern Web Development:

Example. Represent this as XML

CTIS 256 Web Technologies II. Week # 1 Serkan GENÇ

Design and Functional Specification

Personal Profile. Experience. Professional Experience

Stackato PaaS Architecture: How it works and why.

A Model of the Operation of The Model-View- Controller Pattern in a Rails-Based Web Server

Avaya Inventory Management System

GUI and Web Programming

Accessing Data with ADOBE FLEX 4.6

6.170 Tutorial 3 - Ruby Basics

Tutorial JavaScript: Switching panels using a radio button

The full setup includes the server itself, the server control panel, Firebird Database Server, and three sample applications with source code.

James Singletary IV :: Front End Web Developer located in Tampa, Florida

Mobile development with Apache OFBiz. Ean Schuessler, Brainfood

Ruby On Rails. CSCI 5449 Submitted by: Bhaskar Vaish

Introducing Apache Pivot. Greg Brown, Todd Volkert 6/10/2010

How To Test Your Web Site On Wapt On A Pc Or Mac Or Mac (Or Mac) On A Mac Or Ipad Or Ipa (Or Ipa) On Pc Or Ipam (Or Pc Or Pc) On An Ip

Web Development using PHP (WD_PHP) Duration 1.5 months

Coding for Desktop and Mobile with HTML5 and Java EE 7

4.2 Understand Microsoft ASP.NET Web Application Development

opalang - Rapid & Secure Web Development

Building native mobile apps for Digital Factory

Introduction to Server-Side Programming. Charles Liu

Instructor: Betty O Neil

How To Use Query Console

DIPLOMA IN WEBDEVELOPMENT

Bug Report. Date: March 19, 2011 Reporter: Chris Jarabek

Product: DQ Order Manager Release Notes

Business Application Development Platform

Getting Started Developing JavaScript Web Apps. this = that. VT Geospatial Forum 2015

Advanced Web Development SCOPE OF WEB DEVELOPMENT INDUSTRY

MarkLogic Server. Reference Application Architecture Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

Part I: The Road to Single Page Application Development... 1

Web development... the server side (of the force)

latest Release 0.2.6

Pentesting Web Frameworks (preview of next year's SEC642 update)

Load testing with. WAPT Cloud. Quick Start Guide

Login with Amazon. Getting Started Guide for Websites. Version 1.0

Power Tools for Pivotal Tracker

White Paper On. Single Page Application. Presented by: Yatin Patel

The Learn-Verified Full Stack Web Development Program

Handling of "Dynamically-Exchanged Session Parameters"

MASTERTAG DEVELOPER GUIDE

Modern Web Application Framework Python, SQL Alchemy, Jinja2 & Flask

ASP.NET. Web Programming. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

Web Applications: Overview and Architecture

SDN, OpenFlow and the ONF

IMRG Peermap API Documentation V 5.0

Cloud Elements ecommerce Hub Provisioning Guide API Version 2.0 BETA

CSCI110 Exercise 4: Database - MySQL

SwiftScale: Technical Approach Document

Software Requirements Specification

<Insert Picture Here> Michael Hichwa VP Database Development Tools Stuttgart September 18, 2007 Hamburg September 20, 2007

CS555: Distributed Systems [Fall 2015] Dept. Of Computer Science, Colorado State University

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

MEAP Edition Manning Early Access Program Nim in Action Version 1

Sitecore Dashboard User Guide

E-Commerce: Designing And Creating An Online Store

WEB DEVELOPMENT COURSE (PHP/ MYSQL)

X-POS GUIDE. v3.4 INSTALLATION SmartOSC and X-POS

Cache Configuration Reference

WWW. World Wide Web Aka The Internet. dr. C. P. J. Koymans. Informatics Institute Universiteit van Amsterdam. November 30, 2007

Web Cloud Architecture

Welcome to EMP Monitor (Employee monitoring system):

Learning Web App Development

Living Requirements Document: Sniffit

Integrating the F5 BigIP with Blackboard

YouTrack MPS case study

A Quick Introduction to Google's Cloud Technologies

Understanding Evolution's Architecture A Technical Overview

Developing a Web Server Platform with SAPI Support for AJAX RPC using JSON

Building Your First MongoDB Application

Ansible. Configuration management tool and ad hoc solution. Marcel Nijenhof

Deploying the BIG-IP System with VMware vcenter Site Recovery Manager

Transcription:

N2O Most Powerful Erlang Web Framework @5HT

How do I shot Web?

Micro REST Python Flask Ruby Sinatra PHP Silex Scala Scalatra

Concurrency in Mind Ruby Celluloid PHP React PHP phpdaemon Java+Scala Play

SPA Angular Meteor Ember Chaplin Brunch D3 Knockout React Backbone jquery

Functional DSL Scala Lift Erlang Nitrogen Haskell BlazeHtml OCaml Ocsigen F# WebSharper

Clojure Laser Enlive Compojure Ring Hiccup ClojureScript Om http-kit aleph noir JVM

Elixir Weber def action(_, conn) do {:render, [project: "simpletodo"], []} end def add([body: body], _conn) do {:json, [response: "ok"], [{"Content-Type", "application/json"}]} end def wrong(_, _) do {:redirect, "/"} end

Erlang ChicagoBoss DTL Engine Database Connectivity PubSub Ruby on Rails like

Nitrogen N2O ~2000 LOC One Process per Connection Binary Page Construction Zero Bridge GProc Pub/Sub WebSockets, KVS DB

Tuned Layers static and dynamic Routing Path cleaned Query Parser Session Cookies stored in ETS cached DTL Templates optimized Nitrogen DSL rendering HTML Elements binaries JavaScript Actions deferred

Layers Performance components TCP conn (K) PHP5 FCGI Simple Script <?php?> 5 Nitrogen No session, No DSL, DTL 1 N2O Sessions, DSL, DTL 7 N2O Sessions, no DSL, DTL 10 N2O No Sessions, no DSL, DTL 13 On same machine raw webserver performance measured with wrk: NGINX -- 60K Cowboy -- 30K

Measuring Tools requests pages/sec latency (ms) wrk 15K 13628.86 18.88 ab 10K 5464.63 190 httperf 10K 3623.50 200 siege 1K 884.51 430 On same machine raw webserver performance measured with wrk: NGINX -- 60K Cowboy -- 30K

Decreasing Latency From 2x to Deliver HTML ASAP Deferred JavaScript delivery after WebSocket connection established <script> TransitionProcess = '<0.7780.5>' </script> socket.send(["n2o",transitionprocess]).

Dynamic HTML cow

Static HTML nginx

SPA and DTL Render both HTML and JavaScript using DSL : #button { postback = login, source = [ user, pass ] } Or render only JavaScript.. #button { render = script, id = ElementId, postback = login, source = [ user, pass ] }.. when you develop SPA

Render <input value="login" id= "temp563149" type="button"/> $( '#temp563149' ).bind( 'click', function anonymous(event) ws.send(bert.encodebuf({ source: Bert.binary( 'temp563149' ), pickle: Bert.binary('g2gCaINoAmgEZAA...'), linked: [ Bert.tuple(Bert.atom( 'user' ), utf8.tobytearray($( '#user' ).val())), Bert.tuple(Bert.atom( 'pass' ), utf8.tobytearray($( '#pass' ).val())) ] })); });

Elements Plug your JavaScript controls body() -> [ #textboxlist { }, #grid { }, #diagram { }, #histogram { }, #monitor { } ]. and talk with them using BERT through WebSockets

Actions Client Updates are sent as Actions which are evaluated as JavaScript strings render_action(record) -> wf:f("alert(\"~s\");", [wf:js_escape(record#alert.text)]). wf:wire(#alert{text="hello, World!"}). Element render could create Actions Action could include rendered Elements Triggered Action may send Events

JS Compiler 200 LOC Preserves Semantics -compile({parse_transform,shen}). M = lists:foldl(fun(x, Acc) -> Acc + X end, 0, [1,2,3,4]), $ erlc sample.erl m = [1,2,3,4].reduce( function(x,acc) { return acc + x; }, 0);

1. Human Readable Output 2. No Runtimes 3. Strong Dynamic Typing 4. Compact Language, Sane Syntax Synrc Shen, JScala [1,2,3,4] TypeScript [1,2,4] CoffeeScript, LiveScript [1,2,3] Ur, Fay, Roy, Elm, Haxe, F*, WebSharper [3,4] ClojureScript [4] OberonJS [1,3,4] Wisp [1,2,4]

Why Erlang to JS? Validation Rules Business Rules Prototyping Static Content Generation Single Environment

SPA React ERL User = #react{ render = fun(this) -> #h1{body=value(email,this)} end }, CommentList = #react{ props = [{data,[]}], render = fun(this) -> Users = lists:map(fun(item) -> User#react{props=Item} end, value(data,this)), Users end },

SPA React JS var user = React.createClass({ render: function() { return React.DOM.h1(null,value('email',this)); }}); var commentlist = React.createClass({props: {data:[]}, render: function() { var users = value('data',this).map(function(item) { return user({props: item}); }); return users; }});

Erlang AST CMPTBL Brace (Joxa /w Erlang AST) Elixir, Erlang Synrc Shen JavaScript Compiler can handle each Erlang language that compiles to Erlang AST*

DTL Sample main () -> Body = wf : render ( body () ), [ #dtl { file = "login", bindings = [ { body, Body } ] } ]. body () -> [ #span { text = "Login: " }, #textbox { id = user }, #span { text = "Pass: " }, #password { id = pass }, #button { text = "Login", postback = login, source = [ user, pass ] } ]. event ( login ) -> wf : user ( wf : q ( user ) ), wf : redirect ( ).

N2O in Elixir defmodule Sample.Index do def event(:init) do :wf.reg(:room) end def event({:chat,pid}) do pid <- {: message, :wf.q(:message)} end def event(e) do :wf.info('unknown Event ~p',[e]) end def main() do :dtl.new(file: "index", bindings: [title: "Elixir N2O", body: body()]) end def body() do { :ok, pid } = : wf.async(fn() -> loop() end) [ : div.new(id: :history), : textbox.new(id: :message), : button.new(id: :send, body: "Chat", postback: {:chat,pid}, source: [:message]) ] end def loop() do receive do {: message, message} -> : wf.insert_bottom(:history, [ :span.new(body: message), :br.new() ]) : wf.flush(:room) unknown -> : wf.info('unknown Looper Message ~p',[unknown]) end loop() end end

N2O in Joxa (ns lispchat (require erlang joxa-core n2o wf)) (defn+ body() [(n2o/panel {:id :history}) (n2o/textbox {:id :message}) (n2o/button {:id :send} {:body "Chat"} {:postback :chat} {:source [:message]}) ]) (defn+ main() [(n2o/dtl {:app :n2o_sample} {:file "index"} {:bindings [{:title "Title"} {:body (body)}]})]) (defn+ speak(m) (wf/insert_bottom :history (n2o/span {:body m}))) (defn+ event(body) (case body (:init (speak ["Hello" (n2o/br)])) (:chat (speak [(wf/q :message) (n2o/br)])))) (defn+ test() (do (event :init) (wf/info "hello ~p~n" [(main)])))

JSON proplists <-> JSON 243x Library Type Enc Dec ------------- ------- ------ ------- jsonx C NIF 1048 998 jiffy C NIF 2652 2234 yaws2 Erlang 14208 12653 Xen Ready jsonerl Erlang 14549 14899 mochijson2 Erlang 16787 16512 jsx Erlang 27188 18333

JSON PT proplists <=> #rec{} -module(users). -behaviour(n2o_rest). -compile({parse_transform, n2o_rest}). -include("users.hrl"). -rest_record(user). from_json(proplist, #user{}) -> #user{}. to_json(record) -> proplist().

REST Sample -compile({parse_transform, n2o_rest}). -include("users.hrl"). -rest_record(user). init() -> ets:new(users, [public, named_table, {keypos, #user.id}]). populate(users) -> ets:insert(users, Users). exists(id) -> ets:member(users, wf:to_list(id)). get() -> ets:tab2list(users). get(id) -> [User] = ets:lookup(users, wf:to_list(id)), User. delete(id) -> ets:delete(users, wf:to_list(id)). post(#user{} = User) -> ets:insert(users, User); post(data) -> post(from_json(data, #user{})).

KVS REST API POST/PUT kvs:add(#user{}). DELETE kvs:remove(user,2). PUT/PATCH kvs:put(#user{id=2}). GET kvs:entries(feed,user). GET kvs:get(user,2). GET kvs:all(user).

Events From JavaScript Everything is sent as an Event Postback event/1 Control control_event/2 API api_event/3 Handle events in Erlang...

Events Nature Events are enveloped by BERT as #ev{} -record ( ev, { name :: api_event control_event event atom (), payload, trigger, module :: atom () } ). You can define your own entry points

Postback Events Create Page Logic with Postback Events event/1 main() -> [ #button { postback = login } ]. event(login) -> wf:info("logged User: ~p", [wf:user()]).

Control Events Handle Data from Controls with Control Events control_event/2 render_element( E = #myelement { } ) -> do_render( E ). control_event(trigger, Data) -> wf:info("received Data ~p from JavaScript Control ~p", [ Data, Trigger ] ).... when you cteate your own Elements

API Events Wire Erlang and JavaScript with API Events api_event/3 main() -> wf:wire( #api { name = notify, tag = api3 } ), [ ]. api_event(event, Args, Req) -> wf:info( "Received from JavaScript: ~p", [ Args ] ). document.notify('hello from JavaScript').

Community Sources https://github.com/5ht/n2o HTML and TeX Handbook http://synrc.com/framework/web/ IRC FreeNode #N2O