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

  • SEARCH
  • Home
  • 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 5996399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:05:51+00:00 2026-05-23T00:05:51+00:00

Update: The answers from Andrew and Conrad were both equally helpful. The easy fix

  • 0

Update: The answers from Andrew and Conrad were both equally helpful. The easy fix for the timing issue fixed the problem, and caching the bigger object references instead of re-building them every time removed the source of the problem. Thanks for the input, guys.

I’m working with a c# .NET API and for some reason the following code executes what I feel is /extremely/ slowly.

This is the handler for a System.Timers.Timer that triggers its elapsed event every 5 seconds.

private static void TimerGo(object source, System.Timers.ElapsedEventArgs e)
    {
        tagList = reader.GetData(); // This is a collection of 10 objects.

        storeData(tagList); // This calls the 'storeData' method below

    }

And the storeData method:

private static void storeData(List<obj> tagList)
    {
        TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
        long timestamp = (long)t.TotalSeconds;

        foreach (type object in tagList)
        {
            string file = @"path\to\file" + object.name + ".rrd";

            RRD dbase = RRD.load(file);

            // Update rrd with current time timestamp and data.
            dbase.update(timestamp, new object[1] { tag.data });
        }
    }

Am I missing some glaring resource sink? The RRD stuff you see is from the NHawk C# wrapper for rrdtool; in this case I update 10 different files with it, but I see no reason why it should take so long.

When I say ‘so long’, I mean the timer was triggering a second time before the first update was done, so eventually “update 2” would happen before “update 1”, which breaks things because “update 1” has a timestamp that’s earlier than “update 2”.

I increased the timer length to 10 seconds, and it ran for longer, but still eventually out-raced itself and tried to update a file with an earlier timestamp. What can I do differently to make this more efficient, because obviously I’m doing something drastically wrong…

  • 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-23T00:05:52+00:00Added an answer on May 23, 2026 at 12:05 am

    Is there a different RRD file for each tag in your tagList? In your pseudo code you open each file N number of times. (You stated there is only 10 objects in the list thought.) Then you perform an update. I can only assume that you dispose your RRD file after you have updated it. If you do not you are keeping references to an open file.

    If the RRD is the same but you are just putting different types of plot data into a single file then you only need to keep it open for as long as you want exclusive write access to it.

    Without profiling the code you have a few options (I recommend profiling btw)

    Keep the RRD files open

    Cache the opened files to prevent you from having to open, write close every 5 seconds for each file. Just cache the 10 opened file references and write to them every 5 seconds.

    Separate the data collection from data writing

    It appears you are taking metric samples from some object every 5 seconds. If you do not having something ‘tailing’ your file, separate the collection from the writing. Take your data sample and throw it into a queue to be processed. The processor will dequeue each tagList and write it as fast as it can, going back for more lists from the queue.

    This way you can always be sure you are getting ~5 second samples even if the writing mechanism is slowed down.

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

Sidebar

Related Questions

UPDATE I have combined various answers from here into a 'definitive' answer on a
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
Update: Based on the answers I initially went the route of using IsInstanceOf() which
Update: Based on a couple of the answers I have received, I just want
Please read my update at the end of question after reading the answers: I'm
UPDATE Some answers so far have suggested using an adjacency list. How would an
Update: Answers to this question helped me code the open sourced project AlicanC's Modern
I've attempted answers from about 10 existing SO questions to no avail. Using Salman
This seems like a straightforward question, but I haven't had any good answers from
I'm having a problem with deadlock on SELECT/UPDATE on SQL Server 2008. I read

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.