Network | 作业network | 作业Algorithm | thread | java代写 | 代写assignment | 代写lab – COMP301 0 Assignment 1

COMP301 0 Assignment 1

Network | 作业network | 作业Algorithm | thread | java代写 | 代写assignment | 代写lab – 这个题目属于一个network的代写任务, 涵盖了Network/network/Algorithm/thread/java等程序代做方面, 这个项目是lab代写的代写题目

lab代写 代写lab

assignment Objectives:

  • To impress upon you the difference in speed between computation and communication and the potential effect this has on the design of distributed systems.
  • To gain some first-hand experience with programming java socket based distributed applications.
  • To get you to think a little more about extended failure modes after you have written an actual (albeit simple) distributed application
  • To make you aware of some different forms of thread synchronization and the need for them.

Assignment Questions:

[ 6 ] 1. Users will always expect good performance from their applications whether they are distributed or not. This, of course, is why we often need to choose (or develop) more efficient algorithms. In a distributed system, Algorithm efficiency is often significantly impacted by the need to communicate information between the different components of the distributed system (since these components are running on different machines). Different networks can have very different characteristics (as measured by both data transfer rate, informally referred to as bandwidth, and message latency). Do some Internet research to explore this issue. Begin by providing concise definitions for communication latency and bandwidth. Determine what might be rough expected values for latency and bandwidth for network communication over a LAN (Local Area Network), such as one built on Gigabit Ethernet, where hosts are within meters of one another and compare that to expected values for latency and bandwidth for network communication in a WAN (Wide Area Network) such as the Internet where hosts could be 20,000 k m apart. How do you think this affects the type of distributed applications you can realistically build in each environment? (Hint: be sure to think about the type and frequency of communication that might be needed between the application components.) Assuming that a server machine has 2.4GHz cores, that each instruction takes, on average, 2. cycles to execute and that the service being provided in response to each client request takes 15 ,000 instructions to execute, approximately how many orders of magnitude difference is there between the compute time at the server for each request and the communication time when the server must be reached via a LAN vs. a WAN network with characteristics as determined earlier in this question. (Assume the messages exchanged are small.) What does this tell you about the way you must divide up a problem if it is to be solved using distributed computing while still providing acceptable response time to its users?

[1 6 ] 2. In class we used banking as an example of a real-world distributed application with ATMs serving as client machines communicating with a single banking server machine that maintained all the account information. In reality, of course, this is an overly simplistic model of reality but it still has many of the important features that are common to many distributed applications. In this question, you will implement a simple Java-based distributed application that allows clients to create accounts and then deposit into them, check their balances and withdraw from them as needed. The account information (account numbers and corresponding balances) will, of course be maintained on a remote server machine. Your single-threaded server will be run at a well known address (i.e. on a machine whose domain name is known to the clients) and will respond to requests on a port number determined by you and selected from your range of assigned ports (which is available via UMLearn in the Announcements

section). Your server should repeatedly accept connections from clients. For each connection,
your server should accept a single Java String specifying what is to be done (see below),
carry out the requested action and return any needed result before terminating the connection.
There are, naturally, four actions that clients may request that must be supported by your server:
create a new account having a specified (currently non-existing) account number with an initial
zero balance, retrieve the balance corresponding to a given account number, deposit a given
amount into a specified (pre-existing) account number (thereby increasing its balance) and
withdraw a given amount from a specified (pre-existing) account number, if possible, (thereby
decreasing its balance). To simplify things for this first assignment we will assume only whole
dollar amounts so that integer values may be used to store balances. Your server should use a
Java HashTable object to store the Integer-type account numbers and corresponding
Integer-type balances (thereby implementing storage of the banks accounting information).
Persistent storage is not required for this assignment! For a create operation, the server will
first need to ensure that you are not attempting to create a pre-existing account (an error of
which the client will need to be informed). To create a new account the server will need to add
an entry to the hash table for the new account number with an associated zero balance. For a
retrieve operation, the server will need to use the hash table to lookup the specified account
and, if it exists, return the corresponding balance. If the account does not exist, some error
indication must be provided. For a deposit operation, the client will provide both an account
number and the amount to be deposited. If the account exists in the hash table, the balance
should be increased by the corresponding amount. If the account does not exist, this is an error
and the client will need to be informed. Finally, for a withdraw operation, the client will
provide both an account number and the amount to be withdrawn. If the account does not exist
in the hash table, this is an error and the client will need to be informed. If the account does
exist in the hash table, the balance should normally be decreased by the corresponding amount,
however, trying to withdraw more money than the account contains is also an error situation
that must be handled. Naturally, the effect(s) of operations done by one client must be visible
to other clients when they connect to the server. The first thing you need to do is to define a
protocol (i.e. agreement on data formats, etc.) to be used for communication between clients
and the server that specifies how the requests will be encoded in messages and also how
responses (and error indications) will be provided. You will also need to implement a simple
command-line based client (also in Java) that supports manual create , retrieve , deposit
and withdraw operations entered at the keyboard by the user. The syntax for these commands
must be C<account>, R< account>, D<account,amount> and W<account,amount>.
(e.g. D<1234,27> would result in 27 dollars being deposited into account number 1234.) The
client must also recognize an E command used to exit the client. This client program will
facilitate the testing of your code by the markers. You are free to start with the example socket
code covered in class and available on the course homepage in UMLearn and modify it to
implement the banking application functionality just described.

[ 12 ] 3. Re-implement your server from Question 2 using Java Threads to support multiple, concurrent clients. Note that no changes should be required to your client code. You are free to modify the skeletal Java multi-threaded server code provided in UMLearn. You need to be conscious of the fact that concurrent Threads will now be accessing your servers data structures and to take actions to ensure that the results of the clients requests are correct.

[ 10 ] 4. Re-implement your client and server from Question 3 to use datagram rather than stream sockets. Again, you are free to modify the example code (this time for DatagramSockets) discussed in class and available in UMLearn. Of course, concurrency is still a concern. Do not leave this question to the last minute as it may not be as straightforward as you expect.

[5] 5. As you know, extended failure modes must be considered when implementing distributed systems. You have now developed a simple multi-threaded server using both connection- oriented (stream) and connectionless (datagram) sockets. Briefly discuss the types of extended failures that could occur in each implementation. Can some failures occur in one implementation but not the other? Explain!

[ 6 ] 6. In class, we talked about the need to synchronize concurrent threads/processes whenever they access shared data and we saw how mutex/lock variables and Javas synchronized methods could be used to provide a common type of synchronization mutually exclusive access. Such mutual exclusion is very useful when the concurrent operations to be synchronized are intended to be independent of one another (e.g. two unrelated requests to some sort of server). Other types of synchronization may also be needed particularly when the concurrent operations are intended to work cooperatively. Consider a distributed computing system where a large problem is somehow divided up so that many machines can be used concurrently to solve parts of the problem. Each machine computes a partial result which is then somehow combined with the results of others to create either a solution or, sometimes, a new problem instance upon which the general process is then repeated until a solution is found. This sort of approach is quite common (though it occurs in various slightly different forms) and includes the currently much-touted map-reduce framework. While mutual exclusion is undoubtedly needed for this sort of approach, other forms of synchronization will also be required. Start by thinking about how a couple of simple problems (e.g. a large scale search or large matrix multiplication) might be divided to benefit from the availability of multiple network-connected machines. Describe your problems and how they would be divided across the machines and then discuss what sort of synchronization would be needed to ensure correct results. Dont worry about how the synchronization is done, just what you think would be needed. A couple of simple diagrams might be useful for answering this question.

Total: 55 marks

You must hand in your assignment electronically via UMLearn using the Assignments functionality
under the Assessments drop-down menu. A folder for the Assignment has been created there. You
can hand in multiple files if so desired. Recall that you must agree to the online honesty document
before the dropbox will be visible. You can read back in the course announcements on UMLearn for
details on how to do this. Assignments are to be done independently unless otherwise explicitly stated
and inclusion of materials from online sites is not allowed. For written questions PDF (.pdf), Word
(.docx), PowerPoint (.pptx), Rich Text Format (.rtf) and Text (.txt) format files are acceptable. Others
are not. Handwritten then scanned PDF files are also not acceptable. For programming questions,
please hand in all source files and any requested results as well as pre-compiled executables for the
target platform. You must also include a text file named README for each programming question
that briefly describes how to both generate and run your program. To be safe, it is best to include your
name and student number in each file handed in. Be aware that the markers will be testing your code
in the  lab environments available in the department (e.g. the Linux lab for A1) so you would be well
advised to ensure that your code and build/run instructions are correct for the test environment.