Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 649083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:54:15+00:00 2026-05-13T21:54:15+00:00

I’m working on an application that does processing at what I’d call fairly high

  • 0

I’m working on an application that does processing at what I’d call fairly high throughput (current peaks in the range of 400 Mbps, design goal of eventual 10 Gbps).

I run multiple instances of a loop which basically just cycles through reading and processing information, and uses a dictionary for holding state. However, i also need to scan the entire dictionary periodically to check for timeouts, and I’d like to solicit some ideas on what to do if this scan becomes a performance hotspot. Basically, what I’m looking for, is if there are any standard techniques for interleaving the timeout checks on the dictionary, with the main processing code in the loop, so that say on loop 1 I check the first dictionary item, loop 2, the second, etc. Also, the dictionary keys change, and will be deleted and added in the main processing code, so it’s not quite as simple as taking a copy of all the dictionary keys and then checking them one by one in the main loop.

I’ll reiterate, this is not a current performance problem. Thus, Please no comments about premature optimizations, I realize it’s premature, I am consciously making the choice to consider this a potential problem.

Edit for clarity: This is a curiosity for me that I’m thinking about it on my weekend, and what a best practices approach might be for something like this. This isn’t the only problem I have, and not the only area of performance I’m looking at. However, this is one area where I’m not really aware of a clean concise way to approach this.

I’m already exploiting parallelism and hardware on this (the next level of hardware is a 5x increase in cost, but more significantly will require a redesign in the parallelism). The parallelism is also working the way I want it to, so again, please it isn’t necessary to comment on this. The dictionary is instantiated per thread, so any additional threads for running the checks would require synchronization between the threads, which is too costly.

Some pseudo code of the logic if it helps:

Dictionary hashdb;
while(true) {
  grab_record_from_buffer(); // There is a buffer in place, so some delays are tolerable
  process(record);  //do the main processing
  update_hashdb();  //Add,remove,update entries in the dictionary
  if(last_scan > 15 seconds)
    foreach(entry in hashdb)
      periodic_check(entry);  //check for timeouts or any other periodic checks on every db entry
}

I do realize I may not run into an actual problem with the way I have it, so there’s a good chance whatever comes up may not require use. However, what I’m really looking for is if there is any standard approach or algorithm for interleaving a dictionary scan with main processing logic, that I’m just not aware of (and the dictionary is changing). Or any suggestions on an approach to this (I do already have an idea how I would approach it, but it’s not as clean as I’d like).

Thank You,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T21:54:15+00:00Added an answer on May 13, 2026 at 9:54 pm

    Are you able to use .NET 4.0 (or at least plan to do so)? If so, ConcurrentDictionary may help you – it allows you to iterate over a dictionary while still modifying it (either in the same thread or a different one).

    You need to be aware that the results may be surprising – you may see some changes but not others, for example – but if that’s acceptable, it may be a useful approach.

    You could then have one thread doing periodic checks for all the other dictionaries. I know you’d previously ruled this out due to synchronization requirements, but the beauty of ConcurrentDictionary is that it doesn’t require synchronization1. Does that change the feasibility of using a separate checking thread?

    If you don’t want to use a separate thread you could use an iterator explicitly – each time you go through the loop, check another entry and start again if you’ve reached the end. Again, this wouldn’t work with a standard dictionary, but should work for a ConcurrentDictionary – so long as you’re willing to work with the possibility of seeing a mixture of updated and stale data.


    1 … by which I mean it doesn’t require any explicit synchronization, and that the internal synchronization is significantly lighter-weight than having to take out a lock around every access.

    From Stephen Toub’s post on ConcurrentDictionary:

    For modifications / writes to the
    dictionary, ConcurrentDictionary
    employs fine-grained locking to ensure
    thread-safety (reads on the dictionary
    are performed in a lock-free manner)

    The other big reduction in locking is the ability mentioned above: you can iterate over the dictionary in one thread while modifying it in another, so long as you can cope with seeing some changes applied since the iterator was created but not others. Compare this with normal Dictionary<,> where for safe concurrent access you’d have to lock the dictionary for the entire time you were iterating over it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 352k
  • Answers 352k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer replace \t with &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;. Each space you want will be… May 14, 2026 at 7:34 am
  • Editorial Team
    Editorial Team added an answer Hm... If I change the line: Mongo m = new… May 14, 2026 at 7:34 am
  • Editorial Team
    Editorial Team added an answer Your file is valid UTF-8, but is not valid XML.… May 14, 2026 at 7:34 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.