# Adaptive Data Synchronization Algorithm for IoT-Oriented Low-Power Wide-Area Networks
## 4 Adaptive File Synchronization
### On Double Signature Efficiency  
The possibility of performing an adaptive chunking shows the importance and efficiency of double signature, to be discussed. In _rsync_-based file synchronization strategies, the size of chunks and signatures employed for data compression is fixed and no parameter variations are expected. As already mentioned in Section 3.2, _rsync_ considers the use of 20-byte signatures (\(d_{R}\) = 4 bytes for the rolling checksum, \(d_{S}\) = 16 bytes for the strong checksum) to compress chunks of dimension typically greater or equal to 500 bytes [23], resulting in a compression ratio \(r_{c}=\dfrac{d}{d_{R}+d_{S}}\geq 15\). This parameter setup is particularly suited to the context where the files to be synchronized are sufficiently large and the percentage of updates is quite low; on the other hand it may be failing when dealing with small-size data subject to significant changes in time. The proposed adaptive chunking algorithm solves part of the problem by dynamically changing the size of the chunk according to the update distribution, but it does not care about signature efficiency. Specifically, when several synchronization procedures consider a large number of changes on the same file, the adaptive chunking algorithm returns a decreasing chunk size \(d\). In this context, having \(d=d_{R}+d_{S}\) represents the signatures performance lower bound, that is where there is no compression gain. Actually, the use of signatures becomes even totally disadvantageous when \(d<d_{R}+d_{S}\) (the chunk is extended instead of compressed). Therefore, to overcome the potential failures of double signature, we present two different solutions for the choice of the most opportune signatures dimension that are driven by the chunk size returned by the previously described algorithm (the essentials are reported in Algorithm 1). * The first strategy considers a lower bound on the chunk dimensioning, that is, given the rolling and strong checksums dimension \(d_{R,ref}\) and \(d_{S,ref}\) respectively, the following condition must be met: \[d_{t+1}>\theta_{c}=d_{R,ref}+d_{S,ref}\] (5) with \(\theta_{c}\) being the reference threshold. Hence Equation (5) represents a sort of additional step to the adaptive chunking algorithm in Section 4.1 that prevents the estimated new chunk size to be smaller than the signatures total dimension. By doing so the benefits of double signature are preserved, but the potential provided by the adaptive chunking algorithm is not fully exploited. Based on the _rsync_ framework we have considered, the proposed chunking algorithm and Equation (5), we refer to the overall file synchronization procedure as Adaptive Chunking rdiff (AC-_rdiff_). * The second proposed approach relies on a threshold-based mechanism offering the possibility to dynamically move from a signature-based procedure to a signatures-free one and vice versa. In particular, the same threshold \(\theta_{c}\) defined as in AC-_rdiff_ is considered to evaluate the convenience of using signatures as follows: \[\text{Synchronization}= \begin{cases}\text{Hashing-free}&\text{if }\ d\leq\theta_{c}\ \to d_{R,t+1}=0;d_{S,t+1}=0\\ \text{Hashing-based}&\text{if }\ d>\theta_{c}\ \to d_{R,t+1}=d_{R,ref};d_{S,t+1}=d_{S, ref}\end{cases} \] (6) If the chunk size is over the threshold \(\theta_{c}\), the signatures-based approach is selected which can bring benefits in terms of data compression. On the other hand, when the chunk dimension is under the reference threshold, the file-scanning procedure for matching detection is performed directly on the _original_ chunks without resorting to any compression. For representation purposes, in Equation (6) and in Algorithms 2 and 3 the dimensions of signatures to be employed in the next \(t+1\) synchronization procedure, namely \(d_{R,t+1}\) and \(d_{S,t+1}\), are set to \(d_{R,ref}\) and \(d_{S,ref}\) for the signature-based approach, and to 0 for the signature-free synchronization.