Socket Programs in Perl

Socket Programs in Perl

Name of Student

Name of Institution

 

 

Date of submission

Socket Programs in Perl Part One

Identify some methods to make a blocking call non-blocking. Discuss the key difference(s) amongst these methods.

The following three methods can be used to block call non-blocking and their key differences are;

Blocking call non-blocking through MVC spring-during a long call, the thread that is responsible in making requests is locked while in the process. As a result of this, the MVC spring is mandated to make long calls that are constantly running to a resource that is not internal where the same requests are then blocked while the server waits for response from non-internal resources.

Blocking call non-blocking through ThreadPoolExecutor.schedule- the program commands an execute code to a separate thread after every one second. However, the programmer is expected to act with caution in order not to make any modifications on the myHashSet. Any form of modification carried at the thread from another independent thread can result into trouble with the locking system.

Blocking callnon-blocking through Plain Vanilla Solution-while forcing modifications in ThreadPoolExtractor, it becomes hard to gain control of several numbers of threads. This causes a lot of harm than good to the server. Contrary to this technique, the plain vanilla solution coordinates threads to allow for control of myHashSet. This allows the program to execute command at the same time control harm to the server.

Use a simple client-server example to illustrate your methods.

Non-blocking REST service with Spring MVC

@RestController

open class ProcessingController [

@RequestMapping{“/process-blocking”}

open ProcessingStatus blockingProcessing{…}[

revisit recent ProcessingStatus{..};

]

]

ScheduledThreadPoolExecutor.scheduleScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor{1};

exec.schedule{recent Runnable{} [

open space run{} [

myHashSet.total{foo};

]

], 1, RunningTime.SECONDS};

The plain vanilla solution

recent Thread{ recent Runnable{} [

open space run{} [

aim [ Thread.rest{ 1000 }; ]

hold {InterruptedException ie} []

myHashSet.total{foo};

]

} ].create{};

Part Two

Write a Perl program to address the following:

It creates a file and writes the integer zero to the file.

# integer

print ” n”;

terminate{0};

]

The program then calls a fork to spawn a child process.

START [

fork and exit; # fork child

print “innern”;

]

print “ inner|n”

print “ outer|n”

]

The parent and child processes alternate incrementing a counter in the file.

On the mother, the screen reads like this:

# unlock simulate{foo, “|-“}

associate pipe_to_fork {$} [

my $parent = shift;

channel my $child, $parent or fail;

my $pid = fork{};

fail “fork{} failed: $!” except defined $pid;

unless {$pid} [

lock $child;

]

or[

lock $parent;

unlock{stdn, “<&=” . fileno{$child}} or fail;

]

$pid;

]

unless{(pipe_to_fork{‘foo’}}[

# parent

print foo “pipe_to_forkn”;

lock foo;

}

else {

# child

while (<stdn>) { print; }

terminate{0};

]

On the child, the screen reads like this:

# unlock simulate{foo, “-|”}

associate pipe_from_fork {$}[

my $parent = shift;

channel $parent, my $child or fail;

my $pid = fork{};

fail “fork{} failed: $!” except defined $pid;

unless {$pid} [

lock $child;

]

else [

lock $parent;

unlock(STDOUT, “>&=” . fileno{$child}} or fail;

]

$pid;

]

unless {pipe_from_fork{‘bar’}} [

# parent

while {<bar>} [ print; ]

lock bar;

]

else [

# child

print “pipe_from_forkn”;

terminate{0};

]

Each time the counter is incremented, print to the console which process, parent or child, is performing the increment.

#+5

print “+5|n”

# child

]

Each process should tell the other process when it has finished its operation. Each process should wait for the other to complete before incrementing the counter.

# +5{foo, “|-“}

associate pipe_to_fork {5} [

my $parent = shift;

channel my $child, $parent or fail;

my $pid = fork{};

fail “fork{} failed: $!” except defined $pid;

unless {$pid} [

lock $child;

]

or[

lock $parent;

unlock{stdn, “<&=” . fileno{$child}} or fail;

]

$pid;

]

unless{(pipe_to_fork{‘foo’}}[

# parent

print foo “pipe_to_forkn”;

lock foo;

}

else {

# child

while (<stdn>) { print; }

finished{0};

]

On the child, the screen reads like this:

# +5{foo, “-|”}

associate pipe_from_fork {5}[

my $parent = shift;

channel $parent, my $child or fail;

my $pid = fork{};

fail “fork{} failed: $!” except defined $pid;

unless {$pid} [

lock $child;

]

else [

lock $parent;

unlock(STDOUT, “>&=” . fileno{$child}} or fail;

]

$pid;

]

unless {pipe_from_fork{‘bar’}} [

# parent

while {<bar>} [ print; ]

lock bar;

]

else [

# child

print “pipe_from_forkn”;

finish{0};

]

The maximum value to which the counter can be incremented is taken as an input from the user.

# maximum integer by user

print “max n”;

]

Discuss any challenges that you have faced in writing your program.

Just like C or any other language used in programming, Perl programming is simple to execute. However, when there is failure in understanding the required procedure by the programmer to command program to execute the intended function a lot of difficulties arise resulting into system inefficiency.

In addition, Perl borrows some concept of C in executing some of its commands, for example in increment and decrement function. It is therefore required that the programmer be equipped with knowledge in C in order to be effective when performing any Perl program operation.

Perl programming is limited in some of its functions as a result of technical difficulties that arise from cloning. This sometimes makes the program complicated to use.