Skip to content
Arjun Dattatray Bhavsar edited this page May 18, 2020 · 10 revisions

Welcome to the Memcached-Lite wiki!

Background:

  • The Memcached- lite is the Server that will provide a stable environment to save and retrieve data.
  • It will save the (Key, Value) pair and maintain the same repository for all the clients connected to the server.
  • The server communicates with clients using TCP as well as UDP connections.
  • This assignment uses a TCP connection to communicate with the server.
  • It only allows the key-value pair to set and get Commands.
  • There are multiple parameters for both the tags
  1. Set – It Has Key, Byte Size, Valid time, and the final value as parameters
  2. Get – It has Key as a parameter which will provide the value for that particular key if available.

Design Details:

This assignment is focused on client-server communication and stable data storage. Server.java is dependent on the client ‘ThreadHandler.java’ class for its execution. Server Functionality: -

  1. Server Creates the Connection using Server Socket using one of the ports.
  2. Then it makes itself available for the clients to connect.
  3. Once the connection comes to the same port, and the address of the server connection gets established.
  4. Then the server assigns the client socket to the Socket object which is used for communication with clients.
  5. The Sockets contain input and output streams that are used to read and write respectively to the stream and send it to the client.
  6. Then socket, Input Stream, and output stream have been provided to thread class.
  7. Thread class takes the string and performs Set, Get operations on the input strings
  8. And Saves the data to the CSV file.
  9. The server as running in the while loop becomes available for new client requests maintaining the concurrency, as we have client 1 in the running state.
  10. Hence By this way server creates a successful concurrent environment to handle multiple clients at a time.
  11. Here if the server gets disconnected, it still maintains the data it has earlier. For which it reads the data once the server loads again, also maintains a stable storage environment.

Server1.java-

  1. It will give Handle all the client requests in a concurrent manner.
  2. Then go to the src directory and run the following commands to start the server. Dashboard

Client Functionality: -

  • The client has very fewer things to worry about as compared to the server.
  • To establish the Connection clients generate the socket and provide the Address of the server and the port number to connect with.
  • If the server is available to connect with then and then only the connection gets setup.
  • Otherwise, it will give an exception as n server is available to connect.
  • To read the data from the server continuously the client runs in the while loop.
  • The client writes the commands in the output stream and retrieves the response of the server in the input stream.
  • It can send the multiple commands to the server and retrieves the response.
  • Multiple such clients can connect to the server at once and run the commands in parallel.
  • The Concurrency is maintained using multithreading.

Client1.java-

  • It’s the java file which will be responsible for generating the client-server interactive session.
  • Client1 accepts the input from the user and sends it to the server and gives a response of the server in the terminal.
  • It will run one command at a time.

To Run:

Go to src folder using Command- cd MemcachedClientServer/src/

Run Following Command to Compile and Run.

Client

Test Cases

TestCase1.java-

  • To test the scaling testCase1.java is used.
  • It’s the client that is used to show the scaling capacity of the server.
  • It will make 1000 set commands in one go
  • The server will respond with stored or not stored.
  • The following is the result of the same.
  • It takes 33.4 seconds to run for 1000 commands to run testCase1

TestCase2.java-

  • It’s the test case to run 1000 get commands in one flow on the single client.
  • It gives the values for all the searched key in the format below. testCase2

TestCase3.java –

  1. Its client which runs 500 set and 500 get commands. testCase3

Concurrency –

1 Have tried connecting 10 clients to the server once – 2) And I am able get the concurrent environment in all 10 clients. Concurrency