Skip to content
GigaSpaces Logo GigaSpaces Logo
  • Products
    • InsightEdge Portfolio
      • Smart Cache
      • Smart ODS
      • Smart Augmented Transactions
    • GigaSpaces Cloud
  • Roles
    • Architects
    • CXOs
    • Product Teams
  • Solutions
    • Industry Solutions
      • Financial Services
      • Insurance
      • Retail and eCommerce
      • Telecommunications
      • Transportations
    • Technical Solutions
      • Operational BI
      • Mainframe & AS/400 Modernization
      • In Memory Data Grid
      • Transactional and Analytical Processing (HTAP)
      • Hybrid Cloud Data Fabric
      • Multi-Tiered Storage
      • Kubernetes Deployment
      • Streaming Analytics for Stateful Apps
  • Customers
  • Company
    • About GigaSpaces
    • Customers
    • Partners
    • Support & Services
      • University
      • Services
      • Support
    • News
    • Contact Us
    • Careers
  • Resources
    • Webinars
    • Blog
    • Demos
    • Solution Briefs & Whitepapers
    • Case Studies
    • Benchmarks
    • ROI Calculators
    • Analyst Reports
    • eBooks
    • Technical Documentation
  • Contact Us
  • Try Free

Guest Post by Patrick May: Scaling the Web Tier

Subscribe to our blog!

Subscribe for Updates
Close
Back

Guest Post by Patrick May: Scaling the Web Tier

GigaSpaces February 26, 2014
4 minutes read

As discussed in previous posts, GigaSpaces XAP supports near linear scalability of distributed data caches and grid processing algorithms. GigaSpaces can also deploy web application servers in the same highly available, self-healing environment in which it manages data caches, distributed computing algorithms, and remote software services.

This example will show how to build, deploy, and access REST services hosted in Jetty instances running in GigaSpaces XAP. If you haven’t yet, you should read my post on simple caching to learn how to configure GigaSpaces XAP and deploy the GigaSpaces infrastructure. All source code for these examples is available on Github.

Example Scenario

The scenario implemented for this example is a REST API that provides SKU (Stock Keeping Unit) data in JSON format. The URLs supported are:

  • /v1/items-by-color/{color} (List items with the specified color)
  • /v1/items-by-size/{size} (List items with the specified size)
  • /v1/items/{color}/{size} (List items with the specified color and size)

The space is primed with SKU objects written by a simple feeder. Once the SKUs are loaded, the web servers can access the data via a standard HttpServlet.

This logic is implemented in three files:

  • SKU.java
  • SKUFeeder.java
  • SKUServlet.java

Deploying the Web Tier

By default, XAP uses Jetty as the web server, but Apache Tomcat is also an option. The unit of deployment for a web application in Gigaspaces XAP is a standard war file, with the addition of a Spring pu.xml file to configure the distributed space:

rest-api.war
  |
  + META-INF
      |
      + spring
          |
          + pu.xml
  |
  + WEB-INF
      |
      + classes
          |
          + . . .
      |
      + lib
          |
          + . . .
      |
      + web.xml
  |
  + images
      |
      + . . .
  |
  + index.html

The pu.xml file simply specifies the configuration of the space holding the data that will be used by the web tier:

. . .
  <os-sla:sla cluster-schema="partitioned-sync2backup"
              number-of-instances="2"
              number-of-backups="1"
              max-instances-per-vm="1"/>
  <os-core:space id="local-proxy" url="/./rest-api-space"/>
  <os-core:distributed-tx-manager id="transaction-manager"/>
  <os-core:giga-space id="space"
                      space="local-proxy"
                      tx-manager="transaction-manager"/>
  <os-core:space id="remote-proxy" url="jini:/*/*/rest-api-space"/>
  <os-core:distributed-tx-manager id="remote-transaction-manager"/>
  <os-core:giga-space id="remoteSpace"
                      space="remote-proxy"
                      tx-manager="remote-transaction-manager"/>
. . . .

For this example, the Jetty instances will run in the same processing units as the space partitions, but will access the distributed space as a whole. This is accomplished by accessing the remote space proxy in SKUServlet.java:

      space_ = (GigaSpace)getServletContext().getAttribute("remoteSpace");

Running the Example

To build and run this example:

  1. Set your JSHOMEDIR environment variable to the GigaSpaces installation directory.
  2. Run ant build to build the example.
  3. Run bin/start-infrastructure.sh to start the GigaSpaces infrastructure
  4. Run bin/deploy.sh to deploy the space and Jetty instances
  5. Run bin/feed.sh to feed SKUs into the space
  6. Point your browser at http://localhost:8081/rest-api/v1/items-by-color/Red to see some data

If you’re intested in seeing the configuration of the infrastructure and the contents of the space, call bin/start-ui.sh

Load Balancing

In this example, with two Jetty instances running, the REST URLs are available on ports 8081 and 8082. If we started four instances, they would range from 8081 to 8084 (the starting port is configurable).

Obviously a web application server needs to provide a single external interface, even if multiple instances are running underneath to ensure reliability. GigaSpaces XAP provides a utility to dynamically update an Apache httpd load balancing configuration to reflect the deployed instances.

Summary

Deploying the web tier in GigaSpaces XAP provides your application with the same high availability and linear scalability that GigaSpaces offers to distributed data caches and common grid computing algorithms. Web server instances can even be spun up and shut down dynamically to handle erratic loads. If you’re looking to learn more about Grid computing with Java, visit our website.

This post implements the simplest possible example of running the web tier in GigaSpaces XAP. As such it has a few limitations, in particular, the constraint that the number of web application server instances must be the same as the number of space primary nodes. That constraint can be eliminated though the use of zones, which will be the topic of my next post.

Patrick May’s Blog

CATEGORIES

  • GigaSpaces
GigaSpaces

All Posts (23)

YOU MAY ALSO LIKE

July 31, 2009

Rapid Data Load
2 minutes read

February 25, 2010

The Missing Piece in the…
13 minutes read

March 25, 2009

My Session at the Banking…
1 minutes read
  • Copied to clipboard

PRODUCTS, SOLUTIONS & ROLES

  • Products
  • InsightEdge Portfolio
    • Smart Cache
    • Smart ODS
    • Smart Augmented Transactions
  • GigaSpaces Cloud
  • Roles
  • Architects
  • CXOs
  • Product Teams
  • Solutions
  • Industry
    • Financial Services
    • Insurance
    • Retail and eCommerce
    • Telecommunications
    • Transportation
  • Technical
    • Operational BI
    • Mainframe & AS/400 Modernization
    • In Memory Data Grid
    • HTAP
    • Hybrid Cloud Data Fabric
    • Multi-Tiered Storage
    • Kubernetes Deployment
    • Streaming Analytics for Stateful Apps

RESOURCES

  • Resource Hub
  • Webinars
  • Blogs
  • Demos
  • Solution Briefs & Whitepapers
  • Case Studies
  • Benchmarks
  • ROI Calculators
  • Analyst Reports
  • eBooks
  • Technical Documentation
  • Featured Case Studies
  • Mainframe Offload with Groupe PSA
  • Digital Transformation with Avanza Bank
  • High Peak Handling with PriceRunner
  • Optimizing Business Communications with Avaya

COMPANY

  • About
  • Customers
  • Management
  • Board Members
  • Investors
  • News
  • Events
  • Careers
  • Contact Us
  • Book A Demo
  • Try GigaSpaces For Free
  • Partners
  • OEM Partners
  • System Integrators
  • Value Added Resellers
  • Technology Partners
  • Support & Services
  • University
  • Services
  • Support
Copyright © GigaSpaces 2021 All rights reserved | Privacy Policy
LinkedInTwitterFacebookYouTube

Contact Us