Added initial parallelism value equal to Total cores/2
authorpkanavos <pkanavos@gmail.com>
Thu, 5 Jul 2012 12:41:47 +0000 (15:41 +0300)
committerpkanavos <pkanavos@gmail.com>
Thu, 5 Jul 2012 12:41:47 +0000 (15:41 +0300)
Now using the parallelism setting in all hash calculations that accept a parallelism setting.

trunk/Pithos.Client.WPF/AppBootstrapper.cs
trunk/Pithos.Core/Agents/Downloader.cs
trunk/Pithos.Core/Agents/Uploader.cs

index da0f2b8..f733e85 100644 (file)
@@ -78,6 +78,7 @@ namespace Pithos.Client.WPF
                {
                        if (Settings.Default.MustUpgrade)
                        {
+                           Settings.Default.HashingParallelism = (byte) (Environment.ProcessorCount/2);
                                Settings.Default.Upgrade();
                                Settings.Default.MustUpgrade = false;
                                Settings.Default.Save();
index 042f109..f7a017e 100644 (file)
@@ -21,6 +21,8 @@ namespace Pithos.Core.Agents
         [Import]\r
         private IStatusKeeper StatusKeeper { get; set; }\r
 \r
+        [Import]\r
+        private IPithosSettings Settings { get; set; }\r
         \r
         public IStatusNotification StatusNotification { get; set; }\r
 \r
@@ -69,7 +71,7 @@ namespace Pithos.Core.Agents
 \r
                         localTreeHash = Signature.CalculateTreeHashAsync(filePath,\r
                                                                             accountInfo.BlockSize,\r
-                                                                            accountInfo.BlockHash, 1,cancellationToken,progress);\r
+                                                                            accountInfo.BlockHash, Settings.HashingParallelism,cancellationToken,progress);\r
                     }\r
 \r
                     var localPath = FileInfoExtensions.GetProperFilePathCapitalization(filePath);\r
@@ -186,7 +188,7 @@ namespace Pithos.Core.Agents
                 StatusNotification.Notify(new StatusNotification(String.Format("Hashing for Download {0} of {1}", d, fileName))));\r
 \r
             //TODO: Should pass cancellation token here\r
-            var treeHash = localTreeHash ?? Signature.CalculateTreeHashAsync(localPath, (int)serverHash.BlockSize, serverHash.BlockHash, 2,cancellationToken,progress);\r
+            var treeHash = localTreeHash ?? Signature.CalculateTreeHashAsync(localPath, (int)serverHash.BlockSize, serverHash.BlockHash, Settings.HashingParallelism,cancellationToken,progress);\r
 \r
             //And compare it with the server's hash\r
             var upHashes = serverHash.GetHashesAsStrings();\r
index 6fbf089..9cbfe2e 100644 (file)
@@ -24,6 +24,9 @@ namespace Pithos.Core.Agents
         [Import]\r
         private IStatusKeeper StatusKeeper { get; set; }\r
 \r
+        [Import]\r
+        private IPithosSettings Settings { get; set; }\r
+\r
         public IStatusNotification StatusNotification { get; set; }\r
 \r
         \r
@@ -55,7 +58,7 @@ namespace Pithos.Core.Agents
                     {\r
                         localTreeHash = Signature.CalculateTreeHashAsync(fileInfo.FullName,\r
                                                                          action.AccountInfo.BlockSize,\r
-                                                                         action.AccountInfo.BlockHash, 1,cancellationToken,progress);\r
+                                                                         action.AccountInfo.BlockHash, Settings.HashingParallelism,cancellationToken,progress);\r
                     }\r
 \r
                     if (fileInfo.Extension.Equals("ignore", StringComparison.InvariantCultureIgnoreCase))\r
@@ -142,67 +145,86 @@ namespace Pithos.Core.Agents
 \r
                             await UnpauseEvent.WaitAsync().ConfigureAwait(false);\r
 \r
-                            if (fileInfo is DirectoryInfo)\r
+                            fileInfo.Refresh();\r
+                            //Does the file still exist or was it deleted/renamed?\r
+                            if (fileInfo.Exists)\r
                             {\r
-                                //If the directory doesn't exist the Hash property will be empty\r
-                                if (String.IsNullOrWhiteSpace(cloudInfo.X_Object_Hash))\r
-                                    //Go on and create the directory\r
-                                    await client.PutObject(account, cloudFile.Container, cloudFile.Name, fullFileName,\r
-                                                         String.Empty, "application/directory");\r
-                                //If the upload is in response to a Folder create with Selective Sync enabled\r
-                                if (action.IsCreation)\r
+                                if (fileInfo is DirectoryInfo)\r
                                 {\r
-                                    //Add the folder to the Selected URls\r
-                                    var selectiveUri = new Uri(client.RootAddressUri, cloudFile.Uri);\r
-                                    Selectives.AddUri(accountInfo, selectiveUri);                                    \r
-                                    Selectives.Save(accountInfo);\r
+                                    //If the directory doesn't exist the Hash property will be empty\r
+                                    if (String.IsNullOrWhiteSpace(cloudInfo.X_Object_Hash))\r
+                                        //Go on and create the directory\r
+                                        await\r
+                                            client.PutObject(account, cloudFile.Container, cloudFile.Name, fullFileName,\r
+                                                             String.Empty, "application/directory");\r
+                                    //If the upload is in response to a Folder create with Selective Sync enabled\r
+                                    if (action.IsCreation)\r
+                                    {\r
+                                        //Add the folder to the Selected URls\r
+                                        var selectiveUri = new Uri(client.RootAddressUri, cloudFile.Uri);\r
+                                        Selectives.AddUri(accountInfo, selectiveUri);\r
+                                        Selectives.Save(accountInfo);\r
+                                    }\r
                                 }\r
-                            }\r
-                            else\r
-                            {\r
+                                else\r
+                                {\r
 \r
-                                var cloudHash = cloudInfo.X_Object_Hash.ToLower();\r
+                                    var cloudHash = cloudInfo.X_Object_Hash.ToLower();\r
 \r
-                                string topHash;\r
-                                TreeHash treeHash;\r
-                                using(StatusNotification.GetNotifier("Hashing {0} for Upload", "Finished hashing {0}",fileInfo.Name))\r
-                                {\r
-                                    treeHash = localTreeHash??action.TreeHash.Value;\r
-                                    topHash = treeHash.TopHash.ToHashString();\r
-                                }\r
+                                    string topHash;\r
+                                    TreeHash treeHash;\r
+                                    using (\r
+                                        StatusNotification.GetNotifier("Hashing {0} for Upload", "Finished hashing {0}",\r
+                                                                       fileInfo.Name))\r
+                                    {\r
+                                        treeHash = localTreeHash ?? action.TreeHash.Value;\r
+                                        topHash = treeHash.TopHash.ToHashString();\r
+                                    }\r
 \r
 \r
 \r
-                                //If the file hashes match, abort the upload\r
-                                if (cloudInfo != ObjectInfo.Empty && (topHash == cloudHash ))\r
-                                {\r
-                                    //but store any metadata changes \r
-                                    StatusKeeper.StoreInfo(fullFileName, cloudInfo);\r
-                                    Log.InfoFormat("Skip upload of {0}, hashes match", fullFileName);\r
-                                    return;\r
-                                }\r
+                                    //If the file hashes match, abort the upload\r
+                                    if (cloudInfo != ObjectInfo.Empty && (topHash == cloudHash))\r
+                                    {\r
+                                        //but store any metadata changes \r
+                                        StatusKeeper.StoreInfo(fullFileName, cloudInfo);\r
+                                        Log.InfoFormat("Skip upload of {0}, hashes match", fullFileName);\r
+                                        return;\r
+                                    }\r
+\r
 \r
+                                    //Mark the file as modified while we upload it\r
+                                    await\r
+                                        StatusKeeper.SetFileOverlayStatus(fullFileName, FileOverlayStatus.Modified).\r
+                                            ConfigureAwait(false);\r
+                                    //And then upload it\r
 \r
-                                //Mark the file as modified while we upload it\r
-                                await StatusKeeper.SetFileOverlayStatus(fullFileName, FileOverlayStatus.Modified).ConfigureAwait(false);\r
-                                //And then upload it\r
+                                    //Upload even small files using the Hashmap. The server may already contain\r
+                                    //the relevant block                                \r
 \r
-                                //Upload even small files using the Hashmap. The server may already contain\r
-                                //the relevant block                                \r
 \r
 \r
+                                    await\r
+                                        UploadWithHashMap(accountInfo, cloudFile, fileInfo as FileInfo, cloudFile.Name,\r
+                                                          treeHash, cancellationToken).ConfigureAwait(false);\r
+                                }\r
 \r
-                                await UploadWithHashMap(accountInfo, cloudFile, fileInfo as FileInfo, cloudFile.Name, treeHash, cancellationToken).ConfigureAwait(false);\r
+                                var currentInfo = client.GetObjectInfo(cloudFile.Account, cloudFile.Container,\r
+                                                                       cloudFile.Name);\r
+                                //If there is no stored ObjectID in the file state, add it\r
+                                if (action.FileState == null || action.FileState.ObjectID == null)\r
+                                {\r
+                                    StatusKeeper.StoreInfo(fullFileName, currentInfo);\r
+                                }\r
+                                else\r
+                                    //If everything succeeds, change the file and overlay status to normal\r
+                                    StatusKeeper.SetFileState(fullFileName, FileStatus.Unchanged,\r
+                                                              FileOverlayStatus.Normal, "");\r
                             }\r
-                            var currentInfo=client.GetObjectInfo(cloudFile.Account, cloudFile.Container, cloudFile.Name);\r
-                            //If there is no stored ObjectID in the file state, add it\r
-                            if (action.FileState == null || action.FileState.ObjectID == null)\r
+                            else\r
                             {\r
-                                StatusKeeper.StoreInfo(fullFileName,currentInfo);\r
+                                StatusKeeper.ClearFileStatus(fullFileName);\r
                             }\r
-                            else                             \r
-                                //If everything succeeds, change the file and overlay status to normal\r
-                                StatusKeeper.SetFileState(fullFileName, FileStatus.Unchanged, FileOverlayStatus.Normal, "");\r
                         }\r
                         catch (WebException exc)\r
                         {\r