SlideShare uma empresa Scribd logo
1 de 43
Baixar para ler offline
Marko Heijnen CODEKITCHEN
Node.js to the rescue

Let Node.js do things when WordPress/PHP isn’t enough
Marko Heijnen
• Founder of CodeKitchen
• Lead developer of GlotPress
• Core contributor for
WordPress
• Plugin developer
• Organizer for WordCamp
Belgrade 2015
• Technologist
Why something else?
Yes, you can build almost
everything in WordPress
But is that the smart
thing to do?
Can you trust on WordPress
to be always stable?
This summer I started moving
things away from WordPress
WP Central
WP Central
• Showing download history
• Showing version usage history
• List all locales and their current state (need update)
• Showing contributors data (currently API only)
• Collects history of locale progress
• Getting checksums for plugins & themes
How it works
• A lot of data handling by wp_remote_get
• Scrapping profiles.WordPress.org to read data
• Multiple API calls to api.WordPress.org
• Combine data so it can be presented
The problem
• Most things happened through WP Cron
• Some things happens on the front end
• Resulting a load on the webserver that could and
should be prevented
New server setup
Loadbalancer
Memcached
Elasticsearch
MariaDB
New server setup
Micro
services
Webserver 1
Webserver 2
Thumbor
Public Private
Service server
• MariaDB as database
• Memcached as object cache
• Moving to Redis when the PHP7 version is out
• Elasticsearch to make search better/faster
The microservices server
• Handles all cronjobs for the network site
• Node.js services running for WP Central
• Like getting checksums for plugins/themes
• Soon merging other WP cronjob calls for getting
all the stats
Microservices
Microservices
• Microservices are small, autonomous services that
work together
• Small, and Focused on Doing One Thing Well
Benefits
• Different services can use different programming
languages
• High level separation
• If WordPress breaks, the services still keep running
• Ease of Deployment
• Scale services that require more resources
Benefits
• In general they have an (REST) API
• Reusable
• Other microservices could call the service to run a
task
Node.js
What is Node.js
• JavaScript platform
• Uses an event-driven, non-blocking I/O model
• Lightweight and efficient
• Ideal for real time application
• Lot’s of modules you can use
• Manage with NPM - https://www.npmjs.org
Why to use it
• Internal webserver
• No configuration needed outside it’s code base
• You could use nginx as a proxy but not needed
• You get what you see approach
Who is using it
• Netflix
Need to know modules
• Express / Restify -> Webserver
• Socket.io -> Real time
• Request -> Doing internet requests
• async -> async calls with callback
• mysql -> MySQL driver with Pool support
• node-cmd -> Command line
Checksums for
plugins/themes
What is does
• Request checksum of a certain version from a
plugin or theme
• Download the zip and unzips it.
• Reads it in memory and get the checksum per
entry
• After everything is retrieved stores it in MySQL
Modules used
• Build in modules

FS

Crypto
• NPM Modules

Express

MySQL

Request

Yauzl for unzipping
• And build a little queue class
Calling the API
• http://wpcentral.io/api/checksums/plugin/tabify-
edit-screen/0.8.3 (REST API)
• Calls nginx by IP (10.10.10.10) which handles as a
fallback when the node.js application is down
• nginx calls then internally the node.js application
like proxy_pass http://127.0.0.1:8080
API calls
• /plugin/:slug/:version

http://10.10.10.10/checksums/plugin/:slug/:version 



http://wpcentral.io/api/checksums/plugin/tabify-
edit-screen/0.8.3
• /theme/:slug/:version

http://10.10.10.10/checksums/theme/:slug/:version



http://wpcentral.io/api/checksums/theme/
twentyfourteen/1.2
nginx rules
error_page 404 @404;

error_page 500 @500;

error_page 502 @502;
location @404 {

internal;

add_header Content-Type application/json always;

return 404 '{ "status": "Route Not Found" }';

}
return 500 '{ "status": "Service is down" }';

return 502 '{ "status": "Service is down" }';
Going over the code
Basic setup
// set variables for environment
var express = require('express'),
app = express(),
mysql = require('mysql'),
request = require('request'),
fs = require('fs'),
crypto = require('crypto'),
yauzl = require("yauzl");
MySQL connection
var pool = mysql.createPool({
connectionLimit : 10,
host : ’10.10.10.11’,
user : 'checksums',
password : 'checksums',
database : 'checksums'
});
pool.on('enqueue', function () {
log_error('Waiting for available connection slot');
});
Server
app.listen(4000);
app.get( '/plugin/:slug/:version', function(req, res) {
if ( ! queue.add( 'plugin', req.params.slug,
req.params.version, res ) ) {
res.json({
'success': false,
'error': 'Generating checksums’
});
}
});
Server 404
app.use(function(req, res, next) {
res.status(404).json({
'success': false,
'error': "Route doesn;'t exist”
});
});
Lets check the rest
Starting the server
• The default way is: node server.js
• The production server way could be:

pm2 start server.js -u www-data --name “Cool service”
The new situation
The new situation
• No more unneeded logic in WordPress
• WordPress simple pipes the calls
• Small services that replacing it
• APIs can easily be reused
• Pushing new updates becomes easier
• Currently no caching but easily added
Other things you could
use node.js for
See my presentation:

Extending WordPress as a pro
Describing an idea of using Socket.io with WordPress
Other ideas
• Scheduling tasks or url
calls
• Build a central cache
point for external
sources like getting
tweets
• Real time support
• git2svn sync
• Backup service
• Real time logger
• Perform heavy tasks
Thank you for
listening
Questions?
@markoheijnen
markoheijnen.com



codekitchen.eu

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Bring api manager into your stack
Bring api manager into your stackBring api manager into your stack
Bring api manager into your stack
 
Realtime with websockets
Realtime with websocketsRealtime with websockets
Realtime with websockets
 
Hidden gems in cf2016
Hidden gems in cf2016Hidden gems in cf2016
Hidden gems in cf2016
 
Command box
Command boxCommand box
Command box
 
Securing applications
Securing applicationsSecuring applications
Securing applications
 
Kickstart Jpa
Kickstart JpaKickstart Jpa
Kickstart Jpa
 
Decoupled Architecture and WordPress
Decoupled Architecture and WordPressDecoupled Architecture and WordPress
Decoupled Architecture and WordPress
 
BP-7 Share Customization Best Practices
BP-7 Share Customization Best PracticesBP-7 Share Customization Best Practices
BP-7 Share Customization Best Practices
 
Workflows and Digital Signatures
Workflows and Digital SignaturesWorkflows and Digital Signatures
Workflows and Digital Signatures
 
Dev objective2015 lets git together
Dev objective2015 lets git togetherDev objective2015 lets git together
Dev objective2015 lets git together
 
Vaadin filtering table example
Vaadin filtering table exampleVaadin filtering table example
Vaadin filtering table example
 
A look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architectureA look at FastCgi & Mod_PHP architecture
A look at FastCgi & Mod_PHP architecture
 
Load Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusionLoad Balancing, Failover and Scalability with ColdFusion
Load Balancing, Failover and Scalability with ColdFusion
 
Locking Down CF Servers
Locking Down CF ServersLocking Down CF Servers
Locking Down CF Servers
 
Super Fast Application development with Mura CMS
Super Fast Application development with Mura CMSSuper Fast Application development with Mura CMS
Super Fast Application development with Mura CMS
 
Introduction to vaadin
Introduction to vaadinIntroduction to vaadin
Introduction to vaadin
 
How to Ensure You're Launching the Most Secure Website - Michael Tremante
How to Ensure You're Launching the Most Secure Website - Michael TremanteHow to Ensure You're Launching the Most Secure Website - Michael Tremante
How to Ensure You're Launching the Most Secure Website - Michael Tremante
 
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignalBuilding modern web sites with ASP .Net Web API, WebSockets and RSignal
Building modern web sites with ASP .Net Web API, WebSockets and RSignal
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
 
Performance tuning of Websites
Performance tuning of WebsitesPerformance tuning of Websites
Performance tuning of Websites
 

Destaque

Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!
Konstantin Obenland
 
Introducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystemIntroducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystem
GGDBologna
 
My first 3 months working with word press
My first 3 months working with word pressMy first 3 months working with word press
My first 3 months working with word press
Noe Lopez
 
Customizing the custom loop wordcamp 2012-jeff
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeff
Alexander Sapountzis
 

Destaque (20)

Wc norrkoping-2015
Wc norrkoping-2015Wc norrkoping-2015
Wc norrkoping-2015
 
Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!Options, and Transients, and Theme Mods — Oh my!
Options, and Transients, and Theme Mods — Oh my!
 
Introducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystemIntroducing the wpXtreme ecosystem
Introducing the wpXtreme ecosystem
 
how to not design like a developer
how to not design like a developerhow to not design like a developer
how to not design like a developer
 
WordPress for Designers
WordPress for DesignersWordPress for Designers
WordPress for Designers
 
Design in WordPress: Three files, unlimited layouts #wcstl
Design in WordPress: Three files, unlimited layouts #wcstlDesign in WordPress: Three files, unlimited layouts #wcstl
Design in WordPress: Three files, unlimited layouts #wcstl
 
SEO para Wordpress (WordCamp Salvador)
SEO para Wordpress (WordCamp Salvador)SEO para Wordpress (WordCamp Salvador)
SEO para Wordpress (WordCamp Salvador)
 
Build your site tonight, be blogging tomorrow
Build your site tonight, be blogging tomorrowBuild your site tonight, be blogging tomorrow
Build your site tonight, be blogging tomorrow
 
WordPress in a Time of Crisis
WordPress in a Time of CrisisWordPress in a Time of Crisis
WordPress in a Time of Crisis
 
Wordpress Plugin Development Practices
Wordpress Plugin Development PracticesWordpress Plugin Development Practices
Wordpress Plugin Development Practices
 
Open Source Entrepreneurship
Open Source EntrepreneurshipOpen Source Entrepreneurship
Open Source Entrepreneurship
 
My first 3 months working with word press
My first 3 months working with word pressMy first 3 months working with word press
My first 3 months working with word press
 
Customize your theme using css
Customize your theme using cssCustomize your theme using css
Customize your theme using css
 
Leveraging Wordpress for an Ecommerce Website
Leveraging Wordpress for an Ecommerce WebsiteLeveraging Wordpress for an Ecommerce Website
Leveraging Wordpress for an Ecommerce Website
 
Customizing the custom loop wordcamp 2012-jeff
Customizing the custom loop   wordcamp 2012-jeffCustomizing the custom loop   wordcamp 2012-jeff
Customizing the custom loop wordcamp 2012-jeff
 
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
 
Can You Go Commercial
Can You Go CommercialCan You Go Commercial
Can You Go Commercial
 
Questions you’re too afraid to ask
Questions you’re too afraid to askQuestions you’re too afraid to ask
Questions you’re too afraid to ask
 
Gerenciamento de sites/blogs com o WordPress 3.4
Gerenciamento de sites/blogs com o WordPress 3.4Gerenciamento de sites/blogs com o WordPress 3.4
Gerenciamento de sites/blogs com o WordPress 3.4
 
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
WordCamp Salvador 2014 - O essencial para o bom desempenho do seu projeto em ...
 

Semelhante a Node.js to the rescue

Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with Faye
Matjaž Lipuš
 

Semelhante a Node.js to the rescue (20)

Extending WordPress as a pro
Extending WordPress as a proExtending WordPress as a pro
Extending WordPress as a pro
 
Advanced Web Technology.pptx
Advanced Web Technology.pptxAdvanced Web Technology.pptx
Advanced Web Technology.pptx
 
Groovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentationGroovy & Grails eXchange 2012 vert.x presentation
Groovy & Grails eXchange 2012 vert.x presentation
 
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - RedmondBuilding APIs with NodeJS on Microsoft Azure Websites - Redmond
Building APIs with NodeJS on Microsoft Azure Websites - Redmond
 
Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?Introduction to Node.js: What, why and how?
Introduction to Node.js: What, why and how?
 
Introduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azureIntroduction to node js - From "hello world" to deploying on azure
Introduction to node js - From "hello world" to deploying on azure
 
.NET Cloud-Native Bootcamp
.NET Cloud-Native Bootcamp.NET Cloud-Native Bootcamp
.NET Cloud-Native Bootcamp
 
Introduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to ChefIntroduction to Infrastructure as Code & Automation / Introduction to Chef
Introduction to Infrastructure as Code & Automation / Introduction to Chef
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
DevOps <3 node.js
DevOps <3 node.jsDevOps <3 node.js
DevOps <3 node.js
 
Node.JS and WebSockets with Faye
Node.JS and WebSockets with FayeNode.JS and WebSockets with Faye
Node.JS and WebSockets with Faye
 
SOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class LibrariesSOLID Programming with Portable Class Libraries
SOLID Programming with Portable Class Libraries
 
Beginners Node.js
Beginners Node.jsBeginners Node.js
Beginners Node.js
 
MVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming modelMVC 6 - the new unified Web programming model
MVC 6 - the new unified Web programming model
 
[Struyf] Automate Your Tasks With Azure Functions
[Struyf] Automate Your Tasks With Azure Functions[Struyf] Automate Your Tasks With Azure Functions
[Struyf] Automate Your Tasks With Azure Functions
 
Apigility-powered API's on IBM i
Apigility-powered API's on IBM iApigility-powered API's on IBM i
Apigility-powered API's on IBM i
 
Deep dive into share point framework webparts
Deep dive into share point framework webpartsDeep dive into share point framework webparts
Deep dive into share point framework webparts
 
Hello world - intro to node js
Hello world - intro to node jsHello world - intro to node js
Hello world - intro to node js
 
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and AngularEscaping the yellow bubble - rewriting Domino using MongoDb and Angular
Escaping the yellow bubble - rewriting Domino using MongoDb and Angular
 
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
Hybrid Mobile Development with Apache Cordova and Java EE 7 (JavaOne 2014)
 

Mais de Marko Heijnen

Bootstrapping your plugin
Bootstrapping your pluginBootstrapping your plugin
Bootstrapping your plugin
Marko Heijnen
 

Mais de Marko Heijnen (20)

Custom coded projects
Custom coded projectsCustom coded projects
Custom coded projects
 
Security, more important than ever!
Security, more important than ever!Security, more important than ever!
Security, more important than ever!
 
My Contributor Story
My Contributor StoryMy Contributor Story
My Contributor Story
 
WooCommerce & Apple TV
WooCommerce & Apple TVWooCommerce & Apple TV
WooCommerce & Apple TV
 
The moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp SofiaThe moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp Sofia
 
Mijn site beveiliging
Mijn site beveiligingMijn site beveiliging
Mijn site beveiliging
 
The moment my site got hacked
The moment my site got hackedThe moment my site got hacked
The moment my site got hacked
 
My complicated WordPress site
My complicated WordPress siteMy complicated WordPress site
My complicated WordPress site
 
Protecting your site by detection
Protecting your site by detectionProtecting your site by detection
Protecting your site by detection
 
GlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.orgGlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.org
 
Writing clean and maintainable code
Writing clean and maintainable codeWriting clean and maintainable code
Writing clean and maintainable code
 
Let's create a multilingual site in WordPress
Let's create a multilingual site in WordPressLet's create a multilingual site in WordPress
Let's create a multilingual site in WordPress
 
Bootstrapping your plugin
Bootstrapping your pluginBootstrapping your plugin
Bootstrapping your plugin
 
The development and future of GlotPress
The development and future of GlotPressThe development and future of GlotPress
The development and future of GlotPress
 
Why Javascript matters
Why Javascript mattersWhy Javascript matters
Why Javascript matters
 
The code history of WordPress
The code history of WordPressThe code history of WordPress
The code history of WordPress
 
Building plugins like a pro
Building plugins like a proBuilding plugins like a pro
Building plugins like a pro
 
Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013
 
Dealing with media
Dealing with mediaDealing with media
Dealing with media
 
The awesome things you can do with images inside WordPress
The awesome things you can do with images inside WordPressThe awesome things you can do with images inside WordPress
The awesome things you can do with images inside WordPress
 

Último

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

Node.js to the rescue

  • 1. Marko Heijnen CODEKITCHEN Node.js to the rescue
 Let Node.js do things when WordPress/PHP isn’t enough
  • 2. Marko Heijnen • Founder of CodeKitchen • Lead developer of GlotPress • Core contributor for WordPress • Plugin developer • Organizer for WordCamp Belgrade 2015 • Technologist
  • 4. Yes, you can build almost everything in WordPress
  • 5. But is that the smart thing to do?
  • 6. Can you trust on WordPress to be always stable?
  • 7. This summer I started moving things away from WordPress
  • 9. WP Central • Showing download history • Showing version usage history • List all locales and their current state (need update) • Showing contributors data (currently API only) • Collects history of locale progress • Getting checksums for plugins & themes
  • 10. How it works • A lot of data handling by wp_remote_get • Scrapping profiles.WordPress.org to read data • Multiple API calls to api.WordPress.org • Combine data so it can be presented
  • 11. The problem • Most things happened through WP Cron • Some things happens on the front end • Resulting a load on the webserver that could and should be prevented
  • 14. Service server • MariaDB as database • Memcached as object cache • Moving to Redis when the PHP7 version is out • Elasticsearch to make search better/faster
  • 15. The microservices server • Handles all cronjobs for the network site • Node.js services running for WP Central • Like getting checksums for plugins/themes • Soon merging other WP cronjob calls for getting all the stats
  • 17. Microservices • Microservices are small, autonomous services that work together • Small, and Focused on Doing One Thing Well
  • 18. Benefits • Different services can use different programming languages • High level separation • If WordPress breaks, the services still keep running • Ease of Deployment • Scale services that require more resources
  • 19. Benefits • In general they have an (REST) API • Reusable • Other microservices could call the service to run a task
  • 21. What is Node.js • JavaScript platform • Uses an event-driven, non-blocking I/O model • Lightweight and efficient • Ideal for real time application • Lot’s of modules you can use • Manage with NPM - https://www.npmjs.org
  • 22. Why to use it • Internal webserver • No configuration needed outside it’s code base • You could use nginx as a proxy but not needed • You get what you see approach
  • 23. Who is using it • Netflix
  • 24. Need to know modules • Express / Restify -> Webserver • Socket.io -> Real time • Request -> Doing internet requests • async -> async calls with callback • mysql -> MySQL driver with Pool support • node-cmd -> Command line
  • 26. What is does • Request checksum of a certain version from a plugin or theme • Download the zip and unzips it. • Reads it in memory and get the checksum per entry • After everything is retrieved stores it in MySQL
  • 27. Modules used • Build in modules
 FS
 Crypto • NPM Modules
 Express
 MySQL
 Request
 Yauzl for unzipping • And build a little queue class
  • 28. Calling the API • http://wpcentral.io/api/checksums/plugin/tabify- edit-screen/0.8.3 (REST API) • Calls nginx by IP (10.10.10.10) which handles as a fallback when the node.js application is down • nginx calls then internally the node.js application like proxy_pass http://127.0.0.1:8080
  • 29. API calls • /plugin/:slug/:version
 http://10.10.10.10/checksums/plugin/:slug/:version 
 
 http://wpcentral.io/api/checksums/plugin/tabify- edit-screen/0.8.3 • /theme/:slug/:version
 http://10.10.10.10/checksums/theme/:slug/:version
 
 http://wpcentral.io/api/checksums/theme/ twentyfourteen/1.2
  • 30. nginx rules error_page 404 @404;
 error_page 500 @500;
 error_page 502 @502; location @404 {
 internal;
 add_header Content-Type application/json always;
 return 404 '{ "status": "Route Not Found" }';
 } return 500 '{ "status": "Service is down" }';
 return 502 '{ "status": "Service is down" }';
  • 32. Basic setup // set variables for environment var express = require('express'), app = express(), mysql = require('mysql'), request = require('request'), fs = require('fs'), crypto = require('crypto'), yauzl = require("yauzl");
  • 33. MySQL connection var pool = mysql.createPool({ connectionLimit : 10, host : ’10.10.10.11’, user : 'checksums', password : 'checksums', database : 'checksums' }); pool.on('enqueue', function () { log_error('Waiting for available connection slot'); });
  • 34. Server app.listen(4000); app.get( '/plugin/:slug/:version', function(req, res) { if ( ! queue.add( 'plugin', req.params.slug, req.params.version, res ) ) { res.json({ 'success': false, 'error': 'Generating checksums’ }); } });
  • 35. Server 404 app.use(function(req, res, next) { res.status(404).json({ 'success': false, 'error': "Route doesn;'t exist” }); });
  • 37. Starting the server • The default way is: node server.js • The production server way could be:
 pm2 start server.js -u www-data --name “Cool service”
  • 39. The new situation • No more unneeded logic in WordPress • WordPress simple pipes the calls • Small services that replacing it • APIs can easily be reused • Pushing new updates becomes easier • Currently no caching but easily added
  • 40. Other things you could use node.js for
  • 41. See my presentation:
 Extending WordPress as a pro Describing an idea of using Socket.io with WordPress
  • 42. Other ideas • Scheduling tasks or url calls • Build a central cache point for external sources like getting tweets • Real time support • git2svn sync • Backup service • Real time logger • Perform heavy tasks