程序代写代做代考 jquery algorithm Java javascript System Design

System Design

The system design is based on client-server architecture. The server side makes use of a popular
nodejs module Express to implement a RESTful API. The client side makes use of jjQuery

library to send request to the server and receive response from it.

The server and client communicates through JSON formatted messages. JSON is a human readable
data format that is very easy for encoding and parsing by Javascript . Since javascript is used as both
server-side and client-side language, the JSON format is very expedient. Since it is human readable, it is
also appropriate for debugging purpose.

Scenario: The cars will regularly send the server their
current position at regular time.

Request Parameters:
car Id
Latitude
Longitude

Action:
Update Car position in the server

Response:
Whether updated successfully

System Design

Server API Design

Car Position Update API

Nearby Cars Search API

Scenario: The client wants to find the nearly cars with a certain
distance from their current position.

Request Parameters:
User Id
Latitude
Longitude

Action:
Search the records of cars positions to find out the
nearby cars.

Response:
Send the list of nearby cars information.

Scenario: The client wants to book a car.

Request Parameters:
User Id
Latitude
Longitude

Action:
Find the nearest available car.

Response:
Send the nearest available car information.

Car Booking API

Price Computation API

Scenario: When the journey ends, the client wants to compute the
price for the journey.

Request Parameters:
Start Latitude
Start Longitude
End Latitude
End Longtitude

Action:
Compute the price.

Response:
Sending the price information.

The front-end is the medium between users and servers. It is responsible for communication on one hand
and the interaction with user on another hand.

The front-end makes use of Google MAP API which is the most popular map provider in the world. It uses
the marker with car icon to indicate car positions.

The front-end will accept user’s input through buttons and text fields, it then sends the HTTP request to the
server using jquery , and updating the UI when receiving the response from server.

Through RESTful API, the client can be relatively independent of the server. The only requirement is
that client sends request according to the RESTful API provided by the server.

Nodejs is itself single-threaded. Although it can be efficient when doing IO intensive stuff through event-
driven and non-blocking I/O model, it can’t take advantage of the multi core when doing CPU intensive
computation.

Since an instance of Nodejs runs on a single thread, the natural solution is to create multiple Nodejs
processes to run on multiple cores.

There is a master process that can create multiple child processes. The master process communicates with
child process through IPC(inter process communication).

The master process continues listening on a port accepting the client’s connections. When a new
connection comes, the master process is responsible to allocation the connection to one of the child

Client Front-end Design

Multi-process

process to do the actual work. A scheduling algorithm such as round robin is implemented to distribute the
work as balanced as possible. Balance means each child process will take largely equal size work.

Another approach is that master creates the listening socket and pass the socket to the child process, the
child process then accepting the connections itself. In this approach, the scheduling of tasks is handled to
the operating system’s process scheduler which may not make a balanced scheduling.

The child process created by master process is also called worker process, because they do the actual
work, whereas master process is responsible for scheduling. The worker processes are independent of
each other. If one worker process fails, others are not affected. As long as there is at least one worker
process, the server can continue to accept new connections.

Designed in this way, we not only can run on multiple cores with multiple processes, it can also give us
more failure-tolerance at the same time.

I create the multi-process car booking system making use of the cluster module. In the master
process, I create the same number of child processes as the number of CPUs. All the worker process will
share the same listening port. Other Application logic are the same with the single-threaded system.

To evaluate the performance of nodejs in single threaded mode and in multi-process mode, I make use
of the module siege to test the system response time under the two different modes. siege is a
benchmark tool that measures server’s performance under duress. It can spawn multiple concurrent client
processes to send multiple HTTP requests at the same time to the server. The siege tool will output the
minimum, maximum, average response time and RPS (request per second). The HTTP request tested for
my system are getposition , book , getPrice and carbooking.html .

Performance Comparison

Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *