Note that there are some explanatory texts on larger screens.

plurals
  1. POCPU utilisation goes to 100% while processing a text file
    primarykey
    data
    text
    <p>I have a master account file having more than 300000 records. This file is having Office, FA, UUID fields along with other fields. We have a webservice which retuns currently enrolled offices for pilot. </p> <p>I need to generate a output file with unique UUIDs from master account file which are part of pilot. The below is my code. </p> <pre><code>public class Job { static Dictionary&lt;string, string&gt; UUIDOfficeFA = new Dictionary&lt;string, string&gt;(); static Dictionary&lt;string, string&gt; UUIDs = new Dictionary&lt;string, string&gt;(); static string PilotOfficeList = string.Empty; /// &lt;summary&gt; /// /// &lt;/summary&gt; public void RunJob() { try { DirectoryInfo directoryInfo = new DirectoryInfo(ConfigurationSettings.AppSettings["AccountFileFolder"]); if (directoryInfo != null || directoryInfo.Exists == false) { FileInfo[] files = directoryInfo.GetFiles(); DateTime lastWrite = DateTime.MinValue; FileInfo lastWritenFile = null; foreach (FileInfo file in files) { if (file.LastWriteTime &gt; lastWrite) { lastWrite = file.LastWriteTime; lastWritenFile = file; } } if (lastWritenFile != null) { if (RetrieveUUIDs(lastWritenFile)) { WriteFile(); } } else { throw new Exception("No matching account file found for processing"); } } } catch (Exception ex) { throw ex; } } static void WriteFile() { try { string FileName = "Testfile_" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; string Path = ConfigurationSettings.AppSettings["TestFolder"] + @"\" + FileName; StringBuilder sb = new StringBuilder(); foreach (KeyValuePair&lt;string, string&gt; kvp in UUIDs) { sb.AppendLine(kvp.Value); } using (StreamWriter writer = File.AppendText(Path)) { writer.Write(sb.ToString()); writer.Flush(); } } catch (Exception ex) { throw ex; } } static bool RetrieveUUIDs(FileInfo file) { try { using (StreamReader sr = file.OpenText()) { string accountFileData = null; accountFileData = sr.ReadToEnd(); string[] str = accountFileData.Trim().Split(new string[] { "\n" }, StringSplitOptions.None); List&lt;string&gt; AccountInfo = new List&lt;string&gt;(str); if (AccountInfo.Count &gt; 0) { TestWebservice client = new TestWebservice(); GetBrancheListRequest request = new GetBrancheListRequest(); GetBrancheListResponse response =client.GetBrancheList(request); if (response != null) { PilotOfficeList = response.GetBrancheListResult; if (string.IsNullOrEmpty(PilotOfficeList)) { throw new Exception("No branch is enrolled for pilot"); } } } foreach (string accountInfo in AccountInfo) { RetrieveUUID(accountInfo); } } } catch (Exception ex) { throw ex; } return true; } private static void RetrieveUUID(string line) { try { string UUID = line.Substring(2, 50).Trim(); string Office = line.Substring(444, 3).Trim(); string FA = line.Substring(447, 3).Trim(); if (!string.IsNullOrEmpty(PilotOfficeList)) { if (!string.IsNullOrEmpty(UUID) || !string.IsNullOrEmpty(Office)) { if (PilotOfficeList.IndexOf(Office) &gt; -1) { if (!UUIDOfficeFA.ContainsKey(UUID + Office + FA)) { UUIDOfficeFA.Add(UUID + Office + FA, UUID + Office + FA); if (!UUIDs.ContainsKey(UUID)) { UUIDs.Add(UUID, UUID); } } } } } } catch (Exception ex) { throw ex; } } } </code></pre> <p>The issue is when this program runs the CPU utilisation goes to 100%. Although entire job completes within 2 minutes but i can't move this on server beacuse it might cause issue for other apps. Please suggest how i can optimize this so that CPU doesn't goes to 100%. </p> <p>Thank you so much for your help in prior.</p> <p>Note- It appears that following are few major CPU utilization points</p> <pre><code>1- accountFileData = sr.ReadToEnd(); 2- string[] str = accountFileData.Trim().Split(new string[] { "\n" }, StringSplitOptions.None); 3- foreach (string accountInfo in AccountInfo) { RetrieveUUID(accountInfo); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload