Git Product home page Git Product logo

ws-vs-xhr's Introduction

Web Sockets vs XHR Showdown

This tool provides a starting point for engineers to compare the power consumption of websockets and XMLHttpRequests in web applications. Clicking the deploy to Heroku button will spin up a dyno capable of serving the test website and receiving data via websockets and an API endpoint.

Deploy

How Does The Test Work?

Connected clients send a heartbeat packet to the server either via a secure web socket connection or XHR which contains information about their User Agent, battery level, and other placeholder content to bulk up the packet size. User's are encouraged to extend the heartbeat packet as needed to ensure an accurate test for their particular use case.

When the server receives a packet, a postgres database records the testID, userAgent, time of receipt, and the battery level (if available). This data can then be queried (eventually by the front end) to determine average battery consumption across a broad range of browsing contexts.

How Is Battery Level Determined?

The user's battery level is determined using the Battery Status API. Not all devices or browsers support this API. In the event a device's battery level cannot be obtained the user will be thanked for their interest in the test and told why they are unable to participate. If the device is actively being charged, the user will be prompted to unplug the charging cable.

Alternative Uses For This Repo

If you're curious to start playing with NodeJS and collecting data in Postgres on Heroku this repo will hopefully serve as a good starting point. It is deliberately verbose and devoid of tooling in an effort to be adaptable. Feel free to ask questions by opening issues. The following links may also be useful:

  • Heroku Postgres: If you use the Heroku Deploy button above, your database will be automatically configured using the db_setup.js script, but it does nothing to setup a local mirror for active development. This document talks about how to do that.
  • Heroku Button Deployment: This page talks about how the above Heroku Button works. You can also review this repo's app.json file.

ws-vs-xhr's People

Contributors

mattsurabian avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.