Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to transfer a 100 GB file that resides on a single server to 100 other servers in the network over 1 Gbps line. What is the best way to do it ? My solution is copy the file to k number of servers(say 9) and then assign the remaining (100-9) servers to each of the of the 9 servers.
This is a way better solution then copying the file from 1 server to 100 sequentially. My question is how to determine k ? or what is the calculation to determine the most efficient value of k. Please suggest if there is any better solution too. sorry forgot to mention .. CANNOT USE TORRENT. not all companies allow for torrent. This is an interview question. Appreciate your response. Thanks
Assuming that you can copy to only one server at a time, it can go as follows.
Main server copies to Server S1.
S1 copies to S2 (1 copy)
S1 copies to S3 and S2 copies to S4 (2 copies in parallel)
S1 copies to S5, S2 copies to S6, S3 copies to S7, S4 copies to S8 (4 copies in parallel)
And so on..
So, the pattern of the number of copies is as follows: 2 pow 0, 2 pow 1, 2 pow 2 etc
1 + 2 + 4 + 8 + 16 + 32 + 64 > 100
So, the number of copies S1 has to do can be found with this formula
(2 pow k >= 100) and (2 pow (k-1) < 100)
In this case, k evaluates to 7 (After the first copy)
Let there be n servers to which the files to be copied. Your approach is correct if copying can be done in parallel, i.e. after the initial round of copying there will be k servers with a copy of the file. If copying from these k servers to the remaining n-k servers can be done in parallel then your approach is ideal.
You can find the value of k as follows,
Select k such that k2 ≤ n and (k+1)2 > n.
One opinion is to multicast file on a network. This way first server will only send file once(and other servers receive the file all simultaneously). It can get really tricky, but I imagine this would be the fastest way. You probably need to devise your own custom protocol, what to do when one computer loses packet.
https://github.com/windsurfer/C-Sharp-Multicast
I know for the interview it may be too late, but for the record perhaps
you could consider something like this:
https://code.google.com/p/castcopy/
or some other multicast copy tool. No need to repeat the packets for each
or some of the receiving clients. You just send one copy of the packet and
all others listen at the same time!
Pan
If you use bittorrent to distribute the file over your lan then the torrent software will take care of load-balancing for you i.e. you don't need to precompute "k." I recommend using utorrent for your clients, but any client will do. Here is a tutorial for setting up the tracker etc
An advantage of using bittorrent is that the recipient servers can start distributing chunks of the file before they have the entire file.
Under simplistic assumptions you could treat this as a dynamic programming problem: for i = 1.. k find the fastest way to produce k copies. At each step consider the time taken to produce k-t copies in previous steps and then add on 1 step to run t copy operations in parallel, where t had better be no larger than k - t.
For the case where k is a power of two, you can produce 2 copies (counting the original) in 1 step, 4 copies in 2 steps... 128 copies in 7 steps, which is quicker than it would take to do the 9 copies that are your first stage, assuming that running 9 copies out of a single machine takes 9 times as long as copying to a single destination.
But all of this assumes that the time taken by a copy depends only on the outgoing bandwidth of the source - in practice I would expect that either all your network links are close together and the same, so that multiple copies at the same time risk slowing each other down, or your network links are widely separated but different, so that copies over different links take different amounts of time.
You should also consider sneakernet - copy to removable USB or removable hard drive and carry the device to its destination for another local copy. Historically, attempting to replace relatives of sneakernet with network links without working out the effective bandwidth of the existing sneakernet have failed by not providing enough network bandwidth.
I can think of Divide and Conquer
100 (50,50) -> (25 , 25) -> (12 , 13) -> (6 , 6) -> (3 ,3) -> (1 , 2) ..STOP
I am assuming the copy function will try to use the local resource (e.g Server 1 to Server 2) Server 1 resource will be used.
So from Server 1 to Server 2 and 3 (total 3 servers)
Now Server 1 to 4 , 2 to 5 , 3 to 6 (total 6 Servers)
Now Server 1 to 7 , 2 to 8 , 3 to 9....6 to 12 (total 12 Servers)
So let's Say a thread manager will copy Server 1 to Server 51 , Server 2 to Server 52 ... Server 50 to Server 100
bzip the file to compress it as much as possible
rsync it to all the other machines
Go for lunch/ Work on the next thing in your stack.
No time limit was mentioned so why assume one. It just makes things harder for yourself.
Two steps:
S00 (server one, the guy having the file initially) splits the file in 100 chunks, not saving the chunks to disk, but instead sending chunks C01-C99 to S01-S99 respectively.
S00-S99 sends their chunk to their siblings, but of cause nobody sends to S00
Expect network to be saturated pretty badly!
Related
I need to measure the datarates of packets between multiple servers. I need pairwise bandwidths between the servers (if possible even the ports), not the overall datarate per interface on each server.
Example output
Timestamp
Server A to B
Server B to A
Server A to C
Server C to A
0
1
2
1
5
1
5
3
7
1
What I tried or thought of
tcpdump - I was capturing all the packets and looking at ip.len for getting the datarates. It worked quite well till I started testing along with TC.
Turns out tcpdump captures packets at a lower layer than TC. So, the bandwidths I measure using this can't see the limit set by TC.
netstat - I tried using this by greping the output and look at Recv-Q and Send-Q columns. But later I found out that it reports the bytes that have been received and are buffered, waiting for the local process that is using this connection to read and consume them. I won't be able to use them to get bandwidth being used.
iftop - Amazing GUI and has all the things I need. But no way to get the output in a good way to process. Might also overwhelm the storage because of the amount of extra text it stores along with.
bwm-ng - Gives overall datarate per interface on each server but not pairwise.
Please let me know if there are any other ways to achieve what I need.
Thanks in advance for your help.
I am trying to read an input file in a cluster environment. Different nodes will read different parts of it. However the parts are not clearly separated, but interleaved in a "grid".
For example, a file with 16 elements (assume integers):
0 1 2 3
4 5 6 7
8 9 A B
C D E F
If I use four nodes, the first node will read the top left 2x2 square (0,1,4,5), the second node will read the top right 2x2 square and so on.
How should I handle this? I can use MPI or OpenMP. I have two ideas but I don't know which would work better:
Each node will open the file and have its own handle to it. Each node would read the file independently, using only the part of the file it needs and skipping over the rest of it. In this case, what would be the difference between using fopen or MPI_File_open? Which one would be better?
Use one node read the whole file and send each part of the input to the node that needs it.
Regarding your question,
I will not suggest the second option you mentioned. that is using one node to read and then distributing the parts. Reasons being this is slow .. especially if the file is large. Here you have twice the overhead, first to keep other processes waiting and second to send the data which is read. So clearly a no go for me.
Regarding your first option, there is no big difference between using fopen and MPI_Fole_open. But Here I will still suggest MPI_File_open to avail certain facilities like non blocking I/O operations and Shared file pointers (makes life easy)
I am writing an application which needs to read thousands (let's say 10000) of small (let's say 4KB) files from a remote location (e.g., an S3 bucket).
The single read from remote takes around 0.1 seconds and processing the file takes just few milliseconds (from 10 to 30). Which is the best solution in terms of performance?
The worse I can do is to download everything serially: 0.1*10000 = 1000 seconds (~16 minutes).
Compressing the files in a single big one would surely help, but it is not an option in my application.
I tried to spawn N threads (where N is the number of logical cores) that download and process 10000/N files each. This gave me 10000/N * 0.1 seconds. If N = 16, it takes indeed around 1 minute to complete
I also tried to spawn K*N threads (this helps sometimes on high latency systems, as GPUs) but I did not get much speed up for any value of K (I tried 2,3,4), maybe due to lot of context thread switching.
My general question is: how would you design such a similar system? Is 1 minute really the best I can achieve?
Thank you,
Giuseppe
I am currently working on a project and I need to test my prototype with repetitive data access patterns. I came across fio which is a flexible I/O tester for Linux (1).
Fio has many options and I want it to produce a workload which accesses the same blocks of a file, the same number of times over and over again. I also need those accesses to not be equal among these blocks. For instance, if fio creates a file named "test.txt"
and this file is divided on 10 blocks, I need the workload to read a specific number of these blocks, with different number of IOs each, over and over again. Let's say that it chooses to access block 3, 7 and 9. Then I want to access these in a specific order and a specific number of times each, over and over again. If this workload can be described by N passes, then I want to be something like this:
1st pass: read block 3 10 times, read block 7 5 times, read block 9 2 times.
2nd pass: read block 3 10 times, read block 7 5 times, read block 9 2 times.
...
N-pass: read block 3 10 times, read block 7 5 times, read block 9 2 times.
Question 1: Can the above workload be produced with Fio? If yes, How?
Question 2: Is there a mailing list, forum, website, community for Fio users?
Thank you,
Nick
http://www.spinics.net/lists/fio/index.html This is the website you can follow mailing list.
http://www.bluestop.org/fio/HOWTO.txt link will also help you.
This is actually quite a tricky thing to do. The closest you'll get with parameters is using one of the non-uniform distributions (see random_distribution in the HOWTO) but you'll be saying re-read blocks A, B, C more than blocks X, Y, Z and you won't be able to control the exact counts.
An alternative is to write an iolog that can be replayed that has the exact sequence you're looking for (see Trace file format v2 in the HOWTO).
Can someone check this calculation?
I want to calculate the speed of my internet connection by downloading a file from a remote server.
My time unit is in 1/60th of a second. Let's say the file on the remote server is 32K.
timeBegin = ticks <- 1/60th of a second since beginning
of some date
get.url( file )
timeEnd =
ticks
Mbps = ( size of file * 8) / ( timeEnd -
timeBegin ) / 60 / 1048576
Does anyone know of a way to test bandwidth (upload/download) from the command line (unix)?
Don't know the exact command off the top to do what you want.
But, you may not get a very accurate reading of your internet BW based on this test.
There are 2 issues I see:
1) You could be limited by latency. Download time is a factor of both latency (the amount of time for a packet to do a round trip between source and destination) and BW.
2) The server and not you may have limited BW.
You probably can get a more accurate number by checking out sights like this:
speakeasy
Your calculation is not quite correct, you are missing some parentheses.
Mbps = ( size of file * 8) / ( ( timeEnd - timeBegin ) / 60 ) / 1048576
I see DasBoot already pointed out some of the potential sources of inaccuracy in this method. I'll just add to #2 that the critical bandwidth limitation may also exist at some hop in between you and the server.
One way I use to check "bandwidth" between servers is to look at the results from scp between remote and local (and vice versa). You could also consider using a large file like 30-40MB...
Another way is to use the wget command which show the speed of download too (like 1Mb/s)
hope it helps
Try to use IPTRAF to monitor it.