question

MarcDibeh-9430 avatar image
0 Votes"
MarcDibeh-9430 asked TimonYang-MSFT edited

Performance issue for dot-net-5.0 on docker running on centos server

I am encountering a performance problem while executing a bash command from dot-net-core 5.0.

  1. I have n files (.csv) in a specific directory

  2. based on some business rules I write n file_name into a (.txt) file

  3. After finishing I execute a shell command from dot-net-core that reads from the file and execute [mv] command which moves the files that their full names are written in the txt file from a location to another.

  4. The action is performing normally! but!

  5. The issue is that I execute the same process with the same resources (file_name.txt) from dot-net-core it took about 2 minutes to finish while the same code is executed from the shell took 11 seconds!



         string source_location = new FileInfo(files.FirstOrDefault()).DirectoryName;
             string tmp_file_name = Guid.NewGuid().ToString().ToUpper();
             string tmp_full_name = Path.Combine(source_location, tmp_file_name) + ".txt";
             File.WriteAllLines(tmp_full_name, files);
             string cmd = $"cat {tmp_full_name} | xargs mv -t  {targetFolder}";
             string time_now = DateTime.Now.ToString();
             Tuple<string, string> result = ShellHelper.Bash(cmd);
             string time_finish = DateTime.Now.ToString();
             string number_of_files = files.Count.ToString();
             log.Info(String.Format("\n [START]: {0} \n [END]: {1} \n [RESULT_BASH]: {2} \n [STATE_BASH]: {3} 
                              \n [NUMBER_OF_FILES]: {4} --------------  \n", time_now, time_finish, result.Item1, 
                                   result.Item2, number_of_files));
    
    
    
      private static class ShellHelper
             {
                 public static Tuple<string, string> Bash(string cmd)
                 {
                     var escapedArgs = cmd.Replace("\"", "\\\"");
        
                     var process = new Process()
                     {
                         StartInfo = new ProcessStartInfo
                         {
                             FileName = "/bin/bash",
                             Arguments = $"-c \"{escapedArgs}\"",
                             RedirectStandardOutput = true,
                             UseShellExecute = false,
                             CreateNoWindow = true
                         }
                     };
        
                     process.Start();
                     string result = process.StandardOutput.ReadToEnd();
                     process.WaitForExit();
        
                     return Tuple.Create(result, process.ExitCode.ToString());
                 }
             }
    



89347-750d00a0-e017-4936-93e1-95d224ebb6e4.txt89348-difference-of-result.txt







dotnet-csharpdotnet-runtimedotnet-ad
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers