I'm trying to simulate this network with NS2:
and I have built the network like this
#Create six nodes
set n0 [$ns node]
set n1 [$ns node]
set n2 [$ns node]
set n3 [$ns node]
set n4 [$ns node]
set n5 [$ns node]
set recvr_delay1 [new RandomVariable/Uniform];
$recvr_delay1 set min_ 5ms
$recvr_delay1 set max_ 25ms
set recvr_delay2 [new RandomVariable/Uniform];
$recvr_delay2 set min_ 5ms
$recvr_delay2 set max_ 25ms
# TODO: make these delays random
#Create links between the nodes
$ns duplex-link $n0 $n2 100Mb 5ms DropTail
$ns duplex-link $n1 $n2 100Mb $recvr_delay1 DropTail
$ns duplex-link $n2 $n3 100Kb 1ms DropTail
$ns duplex-link $n3 $n4 100Mb 5ms DropTail
$ns duplex-link $n3 $n5 100Mb $recvr_delay2 DropTail
and I know that we can set queue-limit for links in NS2:
$ns queue-limit $n0 $n1 10
But the problem is I don't want to set queue-limit for links, I want to set queue limit for those two routers, is there a way to set queue-limit for a node instead of a link?
Based on NS Simulator for Beginners book
"In NS-2, an output queue of a node is implemented as a part of each link whose input is that node. The definition of the link then includes the way to handle overflow at that queue."
I hope it helps.
I wanted to add something to the accepted answer.
you can use two simplex links(same as a duplex link), and only assign queue limit to one of them.
for example suppose we want to make a duplex link between node R and node B:
set R [$ns node]
set B [$ns node]
$ns simplex-link $R $B 1Mb 100ms DropTail
$ns simplex-link $B $R 2Mb 100ms DropTail
$ns queue-limit $R $B 10
Now only node R will have queue limit of 10.
Related
The Kubernetes Scheduler potentialy use a subset of the cluster nodes when trying to schedule a pod, depending on the numbre of nodes in the cluster and the scheduler Configuration.
I wonder what's the default behavior because the kube-scheduler-config API documentation isn't clear:
percentageOfNodesToScore [Required] int32
PercentageOfNodesToScore is the percentage of all nodes that once found feasible for running a pod, the scheduler stops its search for more feasible nodes in the cluster. This helps improve scheduler's performance. Scheduler always tries to find at least "minFeasibleNodesToFind" feasible nodes no matter what the value of this flag is. Example: if the cluster size is 500 nodes and the value of this flag is 30, then scheduler stops finding further feasible nodes once it finds 150 feasible ones. When the value is 0, default percentage (5%--50% based on the size of the cluster) of the nodes will be scored.
The scheduler default behavior in kubernetes 1.25 is enabled when KubeSchedulerConfiguration percentageOfNodesToScore it's set to 0).
The default behavior is to scan 50% of the nodes, that percentage is reduced by the number of nodes in the cluster divided by 125 (exemple: 2500 nodes/125=20 => 50% - 20 point => scan 30% of the nodes). The minimum of nodes to scan is 5% of the total OR 100 nodes.
To fully understand the scheduler behavior, dive into the Kubernetes source code. The function numFeasibleNodesToFind (link to kubernetes 1.25)
const (
// SchedulerError is the reason recorded for events when an error occurs during scheduling a pod.
SchedulerError = "SchedulerError"
// Percentage of plugin metrics to be sampled.
pluginMetricsSamplePercent = 10
// minFeasibleNodesToFind is the minimum number of nodes that would be scored
// in each scheduling cycle. This is a semi-arbitrary value to ensure that a
// certain minimum of nodes are checked for feasibility. This in turn helps
// ensure a minimum level of spreading.
minFeasibleNodesToFind = 100
// minFeasibleNodesPercentageToFind is the minimum percentage of nodes that
// would be scored in each scheduling cycle. This is a semi-arbitrary value
// to ensure that a certain minimum of nodes are checked for feasibility.
// This in turn helps ensure a minimum level of spreading.
minFeasibleNodesPercentageToFind = 5
)
// == trucated == //
// numFeasibleNodesToFind returns the number of feasible nodes that once found, the scheduler stops
// its search for more feasible nodes.
func (sched *Scheduler) numFeasibleNodesToFind(numAllNodes int32) (numNodes int32) {
if numAllNodes < minFeasibleNodesToFind || sched.percentageOfNodesToScore >= 100 {
return numAllNodes
}
adaptivePercentage := sched.percentageOfNodesToScore
if adaptivePercentage <= 0 {
basePercentageOfNodesToScore := int32(50)
adaptivePercentage = basePercentageOfNodesToScore - numAllNodes/125
if adaptivePercentage < minFeasibleNodesPercentageToFind {
adaptivePercentage = minFeasibleNodesPercentageToFind
}
}
numNodes = numAllNodes * adaptivePercentage / 100
if numNodes < minFeasibleNodesToFind {
return minFeasibleNodesToFind
}
return numNodes
}
I use wrk to test cluster performance,both wrk and pod(nginx) are on the same vm。
1、wrk->podIp
./wrk -H "Connection: Close" -t 4 -c 300 -d30 http://{podIp}:80
Running 30s test # http://{podIp}:80
4 threads and 300 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 20.75ms 24.25ms 838.73ms 97.79%
Req/Sec 2.16k 450.42 3.49k 69.23%
258686 requests in 30.07s, 208.46MB read
Socket errors: connect 0, read 0, write 5, timeout 0
Requests/sec: 8603.95
Transfer/sec: 6.93MB
2、wrk->ClusterIp->pod(only one pod)
10% performance decrease
./wrk -H "Connection: Close" -t 4 -c 300 -d30 http://{ClusterIp}:80
Running 30s test # http://{ClusterIp}:80
4 threads and 300 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 29.38ms 14.66ms 249.18ms 90.07%
Req/Sec 1.90k 351.30 3.31k 72.35%
227505 requests in 30.05s, 183.34MB read
Requests/sec: 7571.81
Transfer/sec: 6.10MB
2、wrk->ClusterIp->pod(2 pods)
30% performance decrease. In theory, the Requests/sec should be close to 17206(8603 * 2)
./wrk -H "Connection: Close" -t 4 -c 300 -d30 http://{ClusterIp}:80
Running 30s test # http://{ClusterIp}:80
4 threads and 300 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 13.15ms 8.93ms 106.11ms 73.09%
Req/Sec 3.00k 1.04k 6.32k 68.75%
356342 requests in 30.10s, 287.16MB read
Requests/sec: 11837.60
Transfer/sec: 9.54MB
my configuratin:
in /etc/sysctl.conf
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_tw_reuse = 1
/etc/security/limits.conf
* soft noproc 102400
* hard noproc 102400
I was trying to implement Q-Learning with neural networks. I've got q-learning with a q-table working perfectly fine.
I am playing a little "catch the cheese" game.
It looks something like this:
# # # # # # # #
# . . . . . . #
# . $ . . . . #
# . . . P . . #
# . . . . . . #
# . . . . . . #
# . . . . . . #
# # # # # # # #
The player p is spawning somewhere on the map. If he hits a wall, the reward will be negative. Lets call that negative reward -R for now.
If the player p hits the dollar sign, the reward will be positive. This positive reward will be +R
In both cases, the game will reset and the player will spawn somewhere randomly on the map.
My neural network architecture looks like this:
-> Inputsize: [1, 8, 8]
Flattening: [1, 1, 64] (So I can use Dense layers)
Dense Layer: [1, 1, 4]
-> Outputsize: [1, 1, 4]
For the learning, I am storing some game samples in a buffer. The buffer maximum size is b_max.
So my training looks like this:
Pick a random number between 0 and 1
If the number is greater than the threshold, choose a random action.
Otherwise pick the action with the highest reward.
Take that action and observe the reward.
Update my neural network by choosing a batch of game samples from the buffer
5.1 Iterate through the batch and train the network as following:
5.2 For each batch. The input to the network is the game state. (Everywhere 0, except at the players position).
5.3 The output error of the output layer will be 0 everywhere except at the output neuron that is equal to the action that has been taking at that sample.
5.4 Here the expected output will be:
(the reward) + (discount_factor * future_reward) (future_reward = max (neuralNetwork(nextState))
5.5 Do everything from the beginning.
The thing is that it just doesn't seem to work properly.
I've an idea on how I could change this so it works but I am not sure if this is "allowed":
Each game decision could be trained until it does exactly what is supposed to do.
Then I would go to the next decision and train on that and so on. How is the training usually done?
I would be very happy if someone could help and give me a detailed explanation on how the training works. Especially when it comes to "how many times do run what loop?".
Greetings,
Finn
This is a map that shows what decision the neural network would like to do on each field:
# # # # # # # # # #
# 1 3 2 0 2 3 3 3 #
# 1 1 1 1 0 2 2 3 #
# 0 0 $ 1 3 0 1 1 #
# 1 0 1 2 1 0 3 3 #
# 0 1 2 3 1 0 3 0 # //The map is a little bit bigger but still it can be seen that it is wrong
# 2 0 1 3 1 0 3 0 # //0: right, 1 bottom, 2 left, 3 top
# 1 0 1 0 2 3 2 1 #
# 0 3 1 3 1 3 1 0 #
# # # # # # # # # #
I am working on a train simulation in simpy and have had success so far with a single train entity following the code below.
The trains processes are sections followed by platforms. Each section and platform has a resource of 1 to ensure that only one train utilises at a time.
However I can't find a way to get around the error below:
When I add in a second train to the simulation there is occasionally the situation where one train waits for an unavailable resource and then a failure occurs on that train while it is waiting.
I end up with an Interrupt: Interrupt() error.
Is there a way around these failing queues for resources?
Any help is much appreciated.
import random
import simpy
import numpy
# Configure parameters for the model
RANDOM_SEED = random.seed() # makes results repeatable
T_MEAN_SECTION = 200.0 # journey time (seconds)
DWELL_TIME = 30.0 # dwell time mean (seconds)
DWELL_TIME_EXPO = 1/DWELL_TIME # for exponential distribution
MTTF = 600.0 # mean time to failure (seconds)
TTF_MEAN = 1/MTTF # for exponential distribution
REPAIR_TIME = 120.0 # mean repair time for when failure occurs (seconds)
REPAIR_TIME_EXPO = 1/REPAIR_TIME # for exponential distribution
NUM_TRAINS = 2 # number of trains to simulate
SIM_TIME_HOURS = 1 # sim time in hours
SIM_TIME_DAYS = SIM_TIME_HOURS/18.0 # number of days to simulate
SIM_TIME = 3600 * 18 * SIM_TIME_DAYS # sim time in seconds (this is used in the code below)
# Defining the times for processes
def Section(): # returns processing time for platform 7 Waterloo to 26 Bank
return T_MEAN_SECTION
def Dwell(): # returns processing time for platform 25 Bank to platform 7 Waterloo
return random.expovariate(DWELL_TIME_EXPO)
def time_to_failure(): # returns time until next failure
return random.expovariate(TTF_MEAN)
# Defining the train
class Train(object):
def __init__(self, env, name, repair):
self.env = env
self.name = name
self.trips_complete = 0
self.num_saf = 0
self.sum_saf = 0
self.broken = False
# Start "running" and "downtime_train" processes for the train
self.process = env.process(self.running(repair))
env.process(self.downtime_train())
def running(self, repair):
while True:
# request section A
request_SA = sectionA.request()
########## SIM ERROR IF FAILURE OCCURS HERE ###########
yield request_SA
done_in_SA = Section()
while done_in_SA:
try:
# going on the trip
start = self.env.now
print('%s leaving platform at time %d') % (self.name, env.now)
# processing time
yield self.env.timeout(done_in_SA)
# releasing the section resource
sectionA.release(request_SA)
done_in_SA = 0 # Set to 0 to exit while loop
except simpy.Interrupt:
self.broken = True
delay = random.expovariate(REPAIR_TIME_EXPO)
print('Oh no! Something has caused a delay of %d seconds to %s at time %d') % (delay, self.name, env.now)
done_in_SA -= self.env.now - start # How much time left?
with repair.request(priority = 1) as request_D_SA:
yield request_D_SA
yield self.env.timeout(delay)
self.broken = False
print('Okay all good now, failure fixed on %s at time %d') % (self.name, env.now)
self.num_saf += 1
self.sum_saf += delay
# request platform A
request_PA = platformA.request()
########## SIM ERROR IF FAILURE OCCURS HERE ###########
yield request_PA
done_in_PA = Dwell()
while done_in_PA:
try:
# platform process
start = self.env.now
print('%s arriving to platform A and opening doors at time %d') % (self.name, env.now)
yield self.env.timeout(done_in_PA)
print('%s closing doors, ready to depart platform A at %d\n') % (self.name, env.now)
# releasing the platform resource
platformA.release(request_PA)
done_in_PA = 0 # Set to 0 to exit while loop
except simpy.Interrupt:
self.broken = True
delay = random.expovariate(REPAIR_TIME_EXPO)
print('Oh no! Something has caused a delay of %d seconds to %s at time %d') % (delay, self.name, env.now)
done_in_PA -= self.env.now - start # How much time left?
with repair.request(priority = 1) as request_D_PA:
yield request_D_PA
yield self.env.timeout(delay)
self.broken = False
print('Okay all good now, failure fixed on %s at time %d') % (self.name, env.now)
self.num_saf += 1
self.sum_saf += delay
# Round trip is finished
self.trips_complete += 1
# Defining the failure event
def downtime_train(self):
while True:
yield self.env.timeout(time_to_failure())
if not self.broken:
# Only break the train if it is currently working
self.process.interrupt()
# Setup and start the simulation
print('Train trip simulator')
random.seed(RANDOM_SEED) # Helps with reproduction
# Create an environment and start setup process
env = simpy.Environment()
# Defining resources
platformA = simpy.Resource(env, capacity = 1)
sectionA = simpy.Resource(env, capacity = 1)
repair = simpy.PreemptiveResource(env, capacity = 10)
trains = [Train(env, 'Train %d' % i, repair)
for i in range(NUM_TRAINS)]
# Execute
env.run(until = SIM_TIME)
Your processes request a resource and never release it. That’s why the second trains waits forever for its request to succeed. While it is waiting, the failure process seems to interrupt the process. That’s why you get an error. Please read the guide to resources to understand how SimPy’s resources work and, especially, how to release a resource when you are done.
Hello Everyone,
I had a problem regarding a Perl Module as I am using this module to retrieve some specific lines form a flat file that contains multiple sets of information as I had mentioned in code.(This is an example code of Bio::Parse::SwissProt.pm). But the problem is that whenever we are working with this code, it has a problem in Refs statement. It is giving an error as modification of read-only value attempted atc:/wamp/bin/perl/site/lib/bio/parse/swissprot.pm line 345. Input file looks like this
Input File(Flate file)
ID P72354_STAAU Unreviewed; 575 AA.
AC P72354;
DT 01-FEB-1997, integrated into UniProtKB/TrEMBL.
DT 01-FEB-1997, sequence version 1.
DT 29-MAY-2013, entry version 79.
DE SubName: Full=ATP-binding cassette transporter A;
GN Name=abcA;
OS Staphylococcus aureus.
OC Bacteria; Firmicutes; Bacilli; Bacillales; Staphylococcus.
OX NCBI_TaxID=1280;
RN [1]
RP NUCLEOTIDE SEQUENCE.
RC STRAIN=NCTC 8325;
RX PubMed=8878592;
RA Henze U.U., Berger-Bachi B.;
RT "Penicillin-binding protein 4 overproduction increases beta-lactam
RT resistance in Staphylococcus aureus.";
RL Antimicrob. Agents Chemother. 40:2121-2125(1996).
RN [2]
RP NUCLEOTIDE SEQUENCE.
RC STRAIN=NCTC 8325;
RX PubMed=9158759;
RA Henze U.U., Roos M., Berger-Bachi B.;
RT "Effects of penicillin-binding protein 4 overproduction in
RT Staphylococcus aureus.";
RL Microb. Drug Resist. 2:193-199(1996).
CC -!- SIMILARITY: Belongs to the ABC transporter superfamily.
CC -----------------------------------------------------------------------
CC Copyrighted by the UniProt Consortium, see http://www.uniprot.org/terms
CC Distributed under the Creative Commons Attribution-NoDerivs License
CC -----------------------------------------------------------------------
DR EMBL; X91786; CAA62898.1; -; Genomic_DNA.
DR ProteinModelPortal; P72354; -.
DR SMR; P72354; 335-571.
DR GO; GO:0016021; C:integral to membrane; IEA:InterPro.
DR GO; GO:0005524; F:ATP binding; IEA:UniProtKB-KW.
DR GO; GO:0042626; F:ATPase activity
DR GO; GO:0006200; P:ATP catabolic process; IEA:GOC.
DR InterPro; IPR003593; AAA+_ATPase.
DR InterPro; IPR003439; ABC_transporter-like.
DR InterPro; IPR017871; ABC_transporter_CS.
DR InterPro; IPR017940; ABC_transporter_type1.
DR InterPro; IPR001140; ABC_transptr_TM_dom.
DR InterPro; IPR011527; ABC_transptrTM_dom_typ1.
DR InterPro; IPR027417; P-loop_NTPase.
DR Pfam; PF00664; ABC_membrane; 1.
DR Pfam; PF00005; ABC_tran; 1.
DR SMART; SM00382; AAA; 1.
DR SUPFAM; SSF90123; ABC_TM_1; 1.
DR SUPFAM; SSF52540; SSF52540; 1.
DR PROSITE; PS50929; ABC_TM1F; 1.
DR PROSITE; PS00211; ABC_TRANSPORTER_1; 1.
DR PROSITE; PS50893; ABC_TRANSPORTER_2; 1.
PE 3: Inferred from homology;
KW ATP-binding; Nucleotide-binding.
SQ SEQUENCE 575 AA; 64028 MW; F7E30A85971719B9 CRC64;
MKRENPLFFL FKKLSWPVGL IVAAITISSL GSLSGLLVPL FTGRIVDKFS VSHINWNLIA
LFGGIFVINA LLSGLGLYLL SKIGEKIIYA IRSVLWEHII QLKMPFFDKN ESGQLMSRLT
DDTKVINEFI SQKLPNLLPS IVTLVGSLIM LFILDWKMTL LTFITIPIFV LIMIPLGRIM
QKISTSTQSE IANFSGLLGR VLTEMRLVKI SNTERLELDN AHKNLNEIYK LGLKQAKIAA
VVQPISGIVM LLTIAIILGF GALEIATGAI TAGTLIAMIF YVIQLSMPLI NLSTLVTDYK
KAVGASSRIY EIMQEPIEPT EALEDSENVL IDDGVLSFEH VDFKYDVKKI LDDVSFQIPQ
GQVSAFVGPS GSGKSTIFNL IERMYEIESG DIKYGLESVY DIPLSKWRRK IGYVMQSNSM
MSGTIRDNIL YGINRHVSDE ELINYAKLAN CHDFIMQFDE GYDTLVGERG LKLSGGQRQR
IDIARSFVKN PDILLLDEAT ANLDSESELK IQEALETLME GRTTIVIANR LSTIKKAGQI
IFLDKGQVTG KGTHSELMAS HAKYKNFVVS QKLTD
//
Script part C:/wamp/bin/perl/bin/perl.exe
use strict;
use warnings;
use Data::Dumper;
use SWISS::Entry;
use Bio::Parse::SwissProt;
my $sp = Bio::Parse::SwissProt->new(FILE =>"me.txt")or die $!;
# Read in all the entries and fill %entries
my $entry_name = $sp->entry_name( );
print "$entry_name\n";
my $seq_len = $sp->seq_len( );
print "$seq_len\n";
$refs = $sw->refs();
$refs = $sw->refs(TITLE => 1, AUTH => 1);
for my $i (0..$#{$refs}) {
print "#{$refs->[$i]}\n";
OUTPUT should be like
[1]
NUCLEOTIDE SEQUENCE.
STRAIN=NCTC 8325;
PubMed=8878592;
Henze U.U., Berger-Bachi B.;
"Penicillin-binding protein 4 overproduction increases beta-lactam
resistance in Staphylococcus aureus.";
Antimicrob. Agents Chemother. 40:2121-2125(1996).
[2]
NUCLEOTIDE SEQUENCE.
STRAIN=NCTC 8325;
PubMed=9158759;
Henze U.U., Roos M., Berger-Bachi B.;
"Effects of penicillin-binding protein 4 overproduction in
Staphylococcus aureus.";
Microb. Drug Resist. 2:193-199(1996).
</code></pre>
After some searching on the internet, it appears that you are using SWISS::Entry from the Swissknife package, and it appears you (or someone) downloaded Bio::Parse::SwissProt as an independent project (not part of BioPerl) from sourceforge. I am not familiar with either of these projects, but you can get the information you want by simply using Bio::SeqIO from BioPerl. Here is an example to get the refs:
#!usr/bin/env perl
use strict;
use warnings;
use Bio::SeqIO;
my $usage = "perl $0 swiss-file\n";
my $infile = shift or die $usage;
my $io = Bio::SeqIO->new(-file => $infile, -format => 'swiss');
my $seqio = $io->next_seq;
my $anno_collection = $seqio->annotation;
for my $key ( $anno_collection->get_all_annotation_keys ) {
my #annotations = $anno_collection->get_Annotations($key);
for my $value ( #annotations ) {
if ($value->tagname eq "reference") {
my $hash_ref = $value->hash_tree;
for my $key (keys %{$hash_ref}) {
print $key,": ",$hash_ref->{$key},"\n" if defined $hash_ref->{$key};
}
}
}
}
Running this gives the information you wanted:
authors: Henze U.U., Berger-Bachi B.
location: Antimicrob. Agents Chemother. 40:2121-2125(1996).
title: "Penicillin-binding protein 4 overproduction increases beta-lactam resistance in Staphylococcus aureus."
pubmed: 8878592
authors: Henze U.U., Roos M., Berger-Bachi B.
location: Microb. Drug Resist. 2:193-199(1996).
title: "Effects of penicillin-binding protein 4 overproduction in Staphylococcus aureus."
pubmed: 9158759
The BioPerl Feature Annotation HOWTO is a helpful page for parsing these types of files. If you want to fetch the entries and then parse them, you can use Bio::DB::Swissprot and add just a couple of lines of code to the above example. I know that is not an answer to your specific problem but it is a solution and you'll find that many people can help you with BioPerl.