Advanced Demonstrations
These six demonstrations show Achieve working and playing well with Node.js, npm packages, databases and services. They also introduce techniques for streaming, distributing work and using available computing resources efficiently.
They are not a separate “advanced Achieve” programming model. Achieve remains the HTTP server and application environment while ordinary Node.js capabilities and third-party packages do the jobs they were designed to do.
Simple to start. Not limited to simple systems.
MySQL presents one of the most common backend scenarios: application code interacting with a database. Separate servlets handle registration and login using the mysql2 npm package.
The demonstration requires a MySQL-compatible database such as MariaDB. The supplied setup.sql creates the small database and table used by the demonstration.
WebSockets adds real-time, bidirectional communication using the ws npm package together with achieve_rooms. The WebSocket server works alongside Achieve on the same server and port, allowing connected clients to exchange messages and participate in rooms.
Cluster uses Node.js built-in node:cluster module to run multiple Achieve workers and make use of multiple CPU cores.
The demonstration compares the same CPU-intensive workload with a single Achieve process and with clustered workers.
XML-SAX demonstrates stream processing using the @nodable/sax npm package. Achieve receives the HTTP request and makes its input stream available to the servlet. The servlet passes that stream to the SAX parser, which processes XML incrementally instead of first loading the complete document into memory.
Distributed Computing extends the streaming idea across servers. The first Achieve server relays the incoming stream to another Achieve server, where a servlet uses @nodable/sax to process the SVG incrementally and stream the result back.
Both servers run on the same computer for the demonstration, but the worker could run on another computer reachable over the network.
SOAP demonstrates delegation to an external service. An Achieve servlet uses the soap npm package to communicate with a SOAP service, receives its result, and adapts that result for the web application.
Running the demonstrations
Install and start the distribution as described in README.md. Use npm start for MySQL and XML/SAX, or the documented specialized command for WebSockets, Cluster, Distributed computing, or SOAP.
Most demonstrations use port 8989. Cluster, Distributed Computing and SOAP also use port 8990, so run one demonstration at a time. MySQL additionally requires a running MySQL-compatible database and the supplied database setup.