• Save
Persevere:  Middleware for Node.js and Server-side JS- June 2011
 

Persevere: Middleware for Node.js and Server-side JS- June 2011

on

  • 2,136 views

Persevere:

Persevere:
Middleware for Node.js and Server-side JS

Statistics

Views

Total Views
2,136
Views on SlideShare
2,136
Embed Views
0

Actions

Likes
1
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • Introduce self, background, “how I got into JavaScript” current roles\nGo around room and get intros from students\n
  • Introduce SitePen; more details are on the next slide.\n
  • SitePen CEO Dylan Schiemann is a Dojo Toolkit co-founder. Many other SitePen employees are core contributors to the Dojo Toolkit and other popular JavaScript projects.\nFOSS = Free Open Source Software\n\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • JSGI is JavaScript gateway interface (like WSGI) for JavaScript middleware, designed to be async\nThis is just an intro to each of the packages, we will look more into them in the coming slides\n\n
  • This is just an intro to each of the packages, we will look more into them in the coming slides\n
  • Show them the parts of the example app in an IDE\nCan refer to examples from wiki as covering different sub-projects\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Show what it provides\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • First example, we list dependencies which match up with arguments passed to the module factory function\nSecond example, we wrap a commonjs module and use the standard CommonJS variables (require, exports)\nThird example we explicitly specify the id of the module. This is used by builds and allows you to include a module as
  • \n
  • \n
  • \n
  • \n
  • \n
  • Let’s look at the pipeline now\n
  • Let’s look at the pipeline now\n
  • Let’s look at the pipeline now\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Protocol Spec here: http://www.whatwg.org/specs/web-socket-protocol/\n
  • \n
  • - Explain LongPolling being a prolonged connection to the server via regular AJAX, dojox.socket designed to allow for maximum flexibility with different protocols while giving back WebSocket-to-long-polling fallback capability\n
  • - Basic example of dojox.socket usage\n
  • - Passes basic socket to dojox.Socket\n
  • \n
  • \n
  • - A basic usage of LongPolling\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • (Disabled by default makes it pretty useless for most apps)\n Chrome and Safari have considered disabling 00 by default if security exploits are found before they implement 07.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Persevere:  Middleware for Node.js and Server-side JS- June 2011 Persevere: Middleware for Node.js and Server-side JS- June 2011 Presentation Transcript

  • Persevere: Middleware for Node.js and Server-side JSDylan SchiemannCEO, SitePen, Inc.Co-founder, Dojo Toolkit© SitePen, Inc. All Rights Reserved
  • Nice to Meet you Dylan Schiemann Co-Founder of Dojo Toolkit CEO, SitePen, Inc. President, Dojo Foundation @dylans @sitepen @dojo© SitePen, Inc. All Rights Reserved
  • © SitePen, Inc. All Rights Reserved
  • SitePen: We help our clients build great apps. Desktop and Mobile Web App Development, Design, Advice Support & Training Strong advocates and contributors of FOSS Works with some amazing companies and organizations:© SitePen, Inc. All Rights Reserved
  • Evolution of Web App Development Web 1.0 Dumb client, smart server Focus on HTML & CSS, "separation of markup and presentation" Web 2.0 Smarter client, smart server, con ict Initial break of many paradigms Search indexing, history, navigation Didnt really account for mobile DOM-centric Ajax: sort of real-time© SitePen, Inc. All Rights Reserved
  • Revolution: Separation of Data and UX You want access to your data, and information in a variety of experiences relevant to your current context Aggregation User Interfaces and experiences Challenging past assumptions statelessness, truly embracing REST abusing markup for "separation of markup and presentation" control and federation of data© SitePen, Inc. All Rights Reserved
  • Multifarious Experiences© SitePen, Inc. All Rights Reserved
  • Considerations for Modern Apps Data vs. presentation Context switching (JavaScript everywhere) Packaging (CommonJS AMD) Testing & monitoring Choice Real-time considerations (Comet/WebSockets, Node.js, Persevere, Dojo) Convenient APIs and approaches to development (Persevere, Dojo)© SitePen, Inc. All Rights Reserved
  • Persevere© SitePen, Inc. All Rights Reserved
  • Persevere REST server for HTML5/Ajax applications JavaScript persistence framework Pluggable storage: MongoDB, Redis, CouchDB, MySQL, etc. Real-time data noti cations High performance, asynchronous, scalable End-to-end JavaScript SSJS: Extends Node.js or Narwhal+Jack (and perhaps Ringo) Choice is good.© SitePen, Inc. All Rights Reserved
  • Persevere Design Philosophy Designed for applications with signi cant client-side logic Thin-server applications, zero to minimal server-side code needed Standards-based, HTTP/REST Promise-based asynchronicity for scalability and composibility Modular design, JavaScript everywhere Each package can be used on its own Some can be used in browser too© SitePen, Inc. All Rights Reserved
  • Packages/Sub-Projects Persevere consists of a number of sub-projects Cohesively come together for full JavaScript end-to-end stack© SitePen, Inc. All Rights Reserved
  • Packages/Sub-Projects Pintura - JSGI based RESTful web framework (standard HTTP middleware API) Perstore - Persistence framework Tunguska - Distributed pub/sub framework with Comet noti cations RQL - Resource Query Language engine Promised-IO - Promise-based IO with cross-platform normalization Patr - Promise-based asynchronous test runner Nodules - Module loader with auto-reload of modules and package dependency resolution© SitePen, Inc. All Rights Reserved
  • Packages/Sub-Projects (cont.) Persevere - Client side data explorer, dependency set Transporter - Transports CommonJS modules to the browser to share modules end-to-end Jsgi-node - JSGI middleware for Node Multi-node - Scales Persevere across multiple process Templify - JavaScript template engine JSON Schema - JSON Schema validator and link handler CommonJS-Utils - CommonJS utility modules© SitePen, Inc. All Rights Reserved
  • Persevere Example Wiki Good starting point Project layout Top level app.js security models, page, page-change wiki media handler© SitePen, Inc. All Rights Reserved
  • Pintura HTTP/REST Interaction GET /Model/id - Get object POST /Model/ - Create object PUT /Model/id - Full update (or create) object POST /Model/id - Incremental update object DELETE /Model/id - Delete object GET /Model/?name=value - Query for objects© SitePen, Inc. All Rights Reserved
  • Pintura Set of Middleware components cross-site request forgery protection cross-domain authentication Many more newApp = MiddleWare(app); // take an app, add functionality appWithProtection = // compose functionality CSRFDetect( Session( Authentication(app) ) );© SitePen, Inc. All Rights Reserved
  • Pintura Security Authentication and delegation to authorization mechanisms Error handling - conversion to HTTP status codes Content negotiation Negotiates best media type for a resource Bulk updates via message/JSON Range requests Uses HTTP range units for data paging© SitePen, Inc. All Rights Reserved
  • Perstore Persistence framework for data model construction Data models API based on HTML5 IndexedDB API (get, query, put, delete) De ne property constraints using JSON Schema Perstore provides validation De ne prototype of objects Provides a transaction manager© SitePen, Inc. All Rights Reserved
  • Perstore Pluggable data stores MongoDB, Redis, CouchDB, MySQL, in-memory Store wrappers used like middleware to add functionality Data models are a store wrapper Chainable querying DataModel.query().eq(“name”, “Smith”).sort(“age”).forEach(function(item){ // act on each item in result set });© SitePen, Inc. All Rights Reserved
  • Persevere Template Using as a starting point for new applications Templates for: Model les Security HTTP con guration© SitePen, Inc. All Rights Reserved
  • Persevere Explorer Data model explorer from the browser Provides visual interface to data Edit data directly in explorer© SitePen, Inc. All Rights Reserved
  • CommonJS Modules First and most important work of CommonJS Very widely implemented NodeJS (V8) Narwhal (Rhino) RingoJS (Rhino) Yabble (browser) Allows components to declare and use dependencies Allows components to export functionality to other modules© SitePen, Inc. All Rights Reserved
  • Modules Basics Three "free variables" free variable is a variable that is part of the scope chain above the current module require - Used to load and reference other modules exports - The object that is exported module - Module metadata© SitePen, Inc. All Rights Reserved
  • require() Module IDs System modules ("sys", "net") Relative IDs resolved relative to current module require(“./sibling”); require(“../parent-sibling”); should be used when possible, improves portability Package/module pattern widely used: require(“some-package/some-module”); Used by NPM, Nodules, RequireJS, others© SitePen, Inc. All Rights Reserved
  • require() greeting.js: exports.getGreeting = function(){ return “Hello, World”; }; hello.js: var getGreeting = require(“./greeting”).getGreeting; exports.hello = function(){ console.log(getGreeting()); }; require(“./hello”).hello();© SitePen, Inc. All Rights Reserved
  • module module.id -> absolute id of current module if(require.main == module) If the current module is the main, executed from command line module.exports - Use to assign new exports Useful for exporting a function module.exports = function MyClass(){...}© SitePen, Inc. All Rights Reserved
  • Circular Dependencies Sometimes very useful Code executes in order, must assign exports before require() if they are to be used circularly math.js: exports.add = function(x,y){ return x+y; }; exports.complex = require(“./math-complex”); math-complex.js: var add = require(“./math”).add; exports.add = function(x,y){ return { real: add(x.real, y.real), imaginary: add(x.imaginary, y.imaginary) }; };© SitePen, Inc. All Rights Reserved
  • AMD - Asynchronous Module De nition CommonJS modules arent optimized for browser use (possible to use them, but non optimal) AMD de nes an API to call to register a module Allows modules to execute in a <script> Loader can generate script tags Bene ts of script tag based: speed - <script> tags are fast debuggability - real stack traces, named scripts in all debuggers x-domain - No extra work for x-domain, works the same© SitePen, Inc. All Rights Reserved
  • AMD Formats // addTen.js define(["math"], function(math){ return function(x){ return math.add(x, 10); }); }); // commonjs-style addTen.js define(function(require, exports){ var math = require("math"); exports.addTen = function(x){ return math.add(x, 10); }); }); // Explicit (used by build): define("addTen", ["math"], function(math){ /*...*/}); // Data: define({message: "Hello, World"});© SitePen, Inc. All Rights Reserved
  • AMD - Asynchronous Module De nition Implementations RequireJS Popular new library, Dojo 1.6 can run on top of it Dojo All Dojo and Dijit modules are in AMD as of 1.6 Works with dojo.require/dojo.provide with default sync loader Nodules, and recently added to Node trunk Supports plugins “text!template.html” to load HTML/text “i18n!message” to load locale speci c data© SitePen, Inc. All Rights Reserved
  • CommonJS Packages A set of modules that work together in a package Speci cation suggests directory structure De nes metadata for a set of modules Very widely used in numerous projects Package manager/package registry NPM Dojo registry coming soon (CPM/CPR)© SitePen, Inc. All Rights Reserved
  • Package Directory Structure lib - Runtime code and resources doc - Documentation test - Unit tests bin - Binaries/scripts© SitePen, Inc. All Rights Reserved
  • Package Metadata De ned in package.json in root directory Describe properties of the package: name version author description maintainers licenses mappings dependencies© SitePen, Inc. All Rights Reserved
  • Dependencies "dependencies" used by closed environments (single set of packages) used by NPM "mappings" used by open environments, reference package by URL Used by Dojo, Nodules // package.json: { "mappings": { "foo": "https://github.com/author/foo/zipball/v1.0.1" }, "dependencies": { "foo": "1.0.1" } }© SitePen, Inc. All Rights Reserved
  • Real Time Applications Enterprise Consumer Reporting Multi-Player Games Monitoring Drawing Collaboration Chat Trading© SitePen, Inc. All Rights Reserved
  • Modern Real Time Technologies Real Time Applications Applications that give you information as it happening Utilize Comet technologies to asynchronously receive messages from server How to get information to the user as fast as possible? Real-time technologies take us further than Ajax ever could© SitePen, Inc. All Rights Reserved
  • Modern Real Time Technologies Real-Time Centric Real-Time Supplemental Applications that are completely based Applications that work better with real- Design on real-time functionality time Examples Chat, Gaming Facebook, Google Docs Maintaining responsiveness over Keeping a lightweight footprint, Challenges various networks/technologies unobstrusive Download size less important, use Approach fastest technology whatever the size. Use lightweight transports only© SitePen, Inc. All Rights Reserved
  • WebSockets Enables real-time web, or Comet WebSocket is a technology providing for bi-directional, full- duplex communications channels, over a single TCP socket. Standardized by the W3C: http://dev.w3.org/html5/websockets/ Uses the ws (unsecure) or wss (secure) protocol Provides open, close, error, and message events Provides send and close methods Browser support will emerge in 2011 once secured© SitePen, Inc. All Rights Reserved
  • On the Server-Side Thread-per-connection server’s don’t scale well Thread’s consume a lot of memory Thread switching is expensive Asynchronous event-loop I/O works great for Comet Node.js, EventMachine, etc. Event queues are fast© SitePen, Inc. All Rights Reserved
  • Message Routing/Delivery Filtering messages is expensive Iterative O(n) performance Topic-based publish/subscribe Hash-based O(1) performance© SitePen, Inc. All Rights Reserved
  • Message Routing/Delivery Filtering example Subscribe to new shoes in our product database function(product){ return product.type == “shoe”} slow Topic-based example Changes can publish multiple topics “type=shoe” (and other changes) subscribe(“type=shoe”) fast© SitePen, Inc. All Rights Reserved
  • Tunguska Persevere module for Node.js based Comet delivery Supports WebSocket Integrates with data model Uses pub/sub based delivery Distributed/multi-server AFL/BSD License https://github.com/kriszyp/tunguska© SitePen, Inc. All Rights Reserved
  • Tunguska Why Pub/Sub? It scales, well-understood Wildcards/Globbing Named events Distributed scaling Designed for Comet Integrates with Pintura use message streams to make subscriptions, send messages Connecting to multiple servers for scalability© SitePen, Inc. All Rights Reserved
  • Thanks! Q&A SitePen sitepen.com Dojo Toolkit dojotoolkit.org Twitter: @dylans @sitepen @dojo© SitePen, Inc. All Rights Reserved