Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hi,

I found the following script many years ago and it's been absolutely invaluable in providing for local or network based block device replication. Part of it's neat beauty is that it's trivial to simply copy & paste the lines on a Linux host's shell prompt. It essentially reads data from both source and either local or remote destination block devices (could be entire drive, partition, md device or in our case a Ceph RBD image) in 4 MiB chunks. If the chunk's md5 checksum matches it skips ahead, otherwise it overwrites that chunk.

We are however increasingly being bottle necked by the MD5 hashing function and were wondering if anyone had recommendations on replacing the calls with something that could perhaps offload the hashing to an Intel CPU's AES instructions.


Local block devices:
export srcdev=`rbd map rbd_ssd/vm-277-disk-0`; [ -z $srcdev ] && exi +t 1 # eg: /dev/rbd47 export dstdev=`rbd map rbd_ssd/vm-472-disk-0`; [ -z $dstdev ] && exi +t 1 # eg: /dev/rbd48 perl -'MDigest::MD5 md5' -ne 'BEGIN{$/=\4194304};print md5($_)' $dst +dev | perl -'MDigest::MD5 md5' -ne 'BEGIN{$/=\4194304};$b=md5($_); read STDIN,$a,16;if ($a eq $b) {print "s"} else {print "c" . $_} +' $srcdev | perl -ne 'BEGIN{$/=\1} if ($_ eq"s") {$s++} else {if ($s) { seek STDOUT,$s*4194304,1; $s=0}; read ARGV,$buf,4194304; print $ +buf}' 1<> $dstdev;

Local source to remote block devices:

On source system:
export remote='root@zajnb01-kvm5f.mirror.ad.company.co.za'; export dstdev=`ssh -i /root/.ssh/rsync_rsa $remote "rbd map rbd_ssd/ +vm-277-disk-0`; [ -z $srcdev ] && exit 1"; # or map the image on the destination host and program the variabl +e manually on the source system, for example: # export dstdev='/dev/rbd320'; ssh -i /root/.ssh/rsync_rsa $remote " perl -'MDigest::MD5 md5' -ne 'BEGIN{\$/=\4194304};print md5(\$_)' $d +stdev | lzop -c" | lzop -dc | perl -'MDigest::MD5 md5' -ne 'BEGIN{$/=\4194304};$b=md5($ +_); read STDIN,$a,16;if ($a eq $b) {print "s"} else {print "c" . $_}' +$srcdev | lzop -c | ssh -i /root/.ssh/rsync_rsa $remote "lzop -dc | perl -ne 'BEGIN{\$/=\1} if (\$_ eq\"s\") {\$s++} else {if (\$s) { seek STDOUT,\$s*4194304,1; \$s=0}; read ARGV,\$buf,4194304; print +\$buf}' 1<> $dstdev";

Unallocated, discarded or trimmed blocks read as zeros so read speeds accelerate to GiB/s levels where Perl's MD5 hashing function then becomes the bottleneck. Another thread (860184) referencing possibly skipping the MD5 check if buffers matched. I presume that wouldn't be easy to do on the network based iteration above although it would still save time one some operations...


Regards
David Herselman


In reply to Could SHA encode faster than MD5? by bbs2web

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 02:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found