Skip to content

Commit 93428c7

Browse files
committed
Added the HttpClient config options into the config file
1 parent 3275d3d commit 93428c7

4 files changed

Lines changed: 29 additions & 10 deletions

File tree

FrmMainApp.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,45 @@ public partial class FrmMainApp : Form
3232
internal static IEnumerable<ETFType>? ETF_Types;
3333

3434
private Configuration _config;
35-
private KeyValueConfigurationCollection _section = new();
35+
private readonly KeyValueConfigurationCollection _settingsSection = new();
3636
private CancellationTokenSource cancellationTokenSource;
3737

3838
private static HttpClient _httpClient = new();
3939

4040
public FrmMainApp()
4141
{
4242
cancellationTokenSource = new CancellationTokenSource();
43+
_config = ConfigurationManager.OpenExeConfiguration(userLevel: ConfigurationUserLevel.None);
44+
_settingsSection = _config.AppSettings.Settings;
4345

4446
InitializeComponent();
4547
GetETFTypesFromCSV();
4648

49+
double pooledConnectionLifetimeSetting = _settingsSection.AllKeys.Contains(value: "PooledConnectionLifetime")
50+
? Convert.ToDouble(value: _settingsSection[key: "PooledConnectionLifetime"].Value)
51+
: 2;
52+
double pooledConnectionIdleTimeoutSetting =
53+
_settingsSection.AllKeys.Contains(value: "PooledConnectionIdleTimeout")
54+
? Convert.ToDouble(value: _settingsSection[key: "PooledConnectionIdleTimeout"].Value)
55+
: 1;
56+
int maxConnectionsPerServerSetting = _settingsSection.AllKeys.Contains(value: "MaxConnectionsPerServer")
57+
? Convert.ToInt32(value: _settingsSection[key: "MaxConnectionsPerServer"].Value)
58+
: 100;
59+
60+
4761
SocketsHttpHandler socketsHandler = new()
4862
{
49-
PooledConnectionLifetime = TimeSpan.FromMinutes(value: 2),
50-
MaxConnectionsPerServer = 100
63+
PooledConnectionLifetime = TimeSpan.FromMinutes(value: pooledConnectionLifetimeSetting),
64+
PooledConnectionIdleTimeout = TimeSpan.FromMinutes(value: pooledConnectionIdleTimeoutSetting),
65+
MaxConnectionsPerServer = maxConnectionsPerServerSetting
5166
};
5267

5368
_httpClient = new HttpClient(handler: socketsHandler);
5469
}
5570

5671
private void FrmMainApp_Load(object sender, EventArgs e)
5772
{
58-
_config = ConfigurationManager.OpenExeConfiguration(userLevel: ConfigurationUserLevel.None);
59-
_section = _config.AppSettings.Settings;
60-
if (_section[key: "Theme"].Value == "Dark") tsmi_DarkishMode.PerformClick();
73+
if (_settingsSection[key: "Theme"].Value == "Dark") tsmi_DarkishMode.PerformClick();
6174

6275
btn_StartScrape.Enabled = true;
6376
btn_Stop.Enabled = false;
@@ -707,7 +720,7 @@ private void tsmi_DarkishMode_Click(object sender, EventArgs e)
707720
HelperVariables.UserSettingUseDarkMode = tsmi_DarkishMode.Checked;
708721
SetAppTheme();
709722

710-
_section[key: "Theme"].Value = HelperVariables.UserSettingUseDarkMode ? "Dark" : "Light";
723+
_settingsSection[key: "Theme"].Value = HelperVariables.UserSettingUseDarkMode ? "Dark" : "Light";
711724

712725
_config.Save(saveMode: ConfigurationSaveMode.Modified);
713726
ConfigurationManager.RefreshSection(sectionName: _config.AppSettings.SectionInformation.Name);

app.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
<configuration>
33
<appSettings>
44
<add key="Theme" value="Light"/>
5+
<add key="PooledConnectionLifetime" value="2"/>
6+
<add key="PooledConnectionIdleTimeout" value="1"/>
7+
<add key="MaxConnectionsPerServer" value="100"/>
58
</appSettings>
69
</configuration>

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
**Build 88xx [202403xx] **
44
- NEW & UPDATED:
55
- I've rewritten the HttpClient handling. Should have read up on the documentation beforehand - no more loops!
6+
- Added the HttpClient config options into the config file, though I strongly suggest not changing them.
67

78
- BUGS & FIXES:
89
- N/A

readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ On that note the app can only collect stuff that's either visibly available on t
4040

4141
### Performance
4242

43-
- The whole data pull is around 4.5GB but it appears to be capped on the server side somewhere around 15-20MB/sec (that's around 200 megabits/sec).
44-
- The whole end-to-end process (assuming favourable conditions) takes around 10-15 mins.
43+
- The data pull is around 4.5GB (cca 22,800 pages at the time of initial publication) but the transfer rate appears to be capped on the server side somewhere around 15-20MB/sec (that's around 200 megabits/sec).
44+
- The end-to-end process (assuming favourable conditions) takes around 10-15 mins.
4545
- The app uses a library (`CompressedMemoryCache.cs`) - the licence of that is contained in the file and was built by Gustavo Augusto Hennig (it's APACHE 2.0 btw)
4646
- It's necessary to use compression on the html pages because storing that many (read: tens of thousands) pages at 200-400kbytes each will eat up memory in no time. My initial tests of letters A-C made the app consume around 5GB RAM w/o compression and sub-1GB w/ compression.
4747
- I did some testing on what I deem is a 'normal' performance laptop, ie a Ryzen 7 PRO 5850U [8x 4370 MHz] w/ 32 GB RAM - the Release (non-Debug that is) version of the app peaked at 25% CPU and (again) around sub-1GB RAM.
@@ -87,7 +87,9 @@ I'm generally happy for anyone competent to add pull requests but I don't always
8787

8888
## Known Issues
8989

90-
- "Ticker" extraction works on the basis of getting whatever's in the last parentheses of the header. This is because HL website doesn't appear to store this info separately. In some rare cases (espc w/ Trusts) this can yield odd results. (e.g. [here](https://www.hl.co.uk/shares/shares-search-results/b/baillie-gifford-us-growth-trust-ord) we'd pick up "USA", which is wrong.)
90+
- "Ticker" extraction works on the basis of getting whatever's in the last parentheses of the header. This is because HL website doesn't appear to store this info separately. In some rare cases (espc w/ Trusts) this can yield odd results. e.g.:
91+
- [here](https://www.hl.co.uk/shares/shares-search-results/b/baillie-gifford-us-growth-trust-ord) we'd pick up "USA", which I'm not sure about, whereas
92+
- [this one](https://www.hl.co.uk/shares/shares-search-results/a/argentina-1-bds-090729-usd1) gets entirely discarded because there's no ticker.
9193
- The "Sector" classification can occasionally mislabel securities as ETFs particularly when their name contains the word "Fund" or "Income". HL doesn't actually have an ETF-flag so the code attempts to decipher what's what. This works around 98% of the cases.
9294

9395
## When reporting bugs please specify

0 commit comments

Comments
 (0)