Skip to content

Removed the thread that watches file changes #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: Development
Choose a base branch
from

Conversation

RandallFlagg
Copy link
Contributor

@RandallFlagg RandallFlagg commented Mar 22, 2025

@Hirogen can you test this and tell me if there are any issues? I don't know all the places this can be reached by and also can't test all of them as most of the time I am on Linux.

Should improve system resources and handle file event much better.

Might affect the following issues: #16, #40, #129, #157.

@Hirogen
Copy link
Collaborator

Hirogen commented Mar 23, 2025

i'll check, first thing that comes to my mind, is a logfile that is loaded from a network drive and updated on said network drive.

I'll test that on Monday, since I don't have that kind of setup at home

@Hirogen
Copy link
Collaborator

Hirogen commented Mar 24, 2025

I'll tested it a little bit

this is version 1.12 version and your branch both have the same result
10 ms writes are impossible to handle currently, logexpert just freezes.
20 lines per 50 ms are impossible to handle currently, logexpert just freezes.
10 lines per 50 ms can be handled but i slows down considerably, but still you can use the ui.
<10 lines per 50ms easily handled.

I tested it also with the version 1.9.0 and
10 ms writes are easily handled, no slowdown, regardless of how many lines (tested with +20) are written in the loaded file, so the changes done are slowing logexpert down or are not very performant.

@Hirogen
Copy link
Collaborator

Hirogen commented Mar 24, 2025

after a little bit more testing, it seems that only this branch is affected by the slow down, so in this branch I'm unable to work on a file that has 20 loglines written into it every 10ms, the UI just freezes

@Hirogen
Copy link
Collaborator

Hirogen commented Mar 24, 2025

string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string filePath = Path.Combine(documentsPath, "output.txt");
int intervalMs = 5000; // Default interval in milliseconds
int lineNumber = 1;
bool exit = false;

Console.Write("Enter write interval in milliseconds (default 5000): ");
string input = Console.ReadLine();
if (int.TryParse(input, out int userInterval) && userInterval > 0)
{
    intervalMs = userInterval;
}

Console.CancelKeyPress += (sender, e) =>
{
    e.Cancel = true;
    exit = true;
};

while (!exit)
{
    // Check for user input without blocking
    if (Console.KeyAvailable)
    {
        string command = Console.ReadLine();
        if (command.StartsWith("setinterval ", StringComparison.OrdinalIgnoreCase))
        {
            string[] parts = command.Split(' ');
            if (parts.Length == 2 && int.TryParse(parts[1], out int newInterval) && newInterval > 0)
            {
                intervalMs = newInterval;
                Console.WriteLine($"Write interval updated to {intervalMs} milliseconds.");
            }
            else
            {
                Console.WriteLine("Invalid interval. Usage: setinterval <milliseconds>");
            }
        }
        else if (command.Equals("exit", StringComparison.OrdinalIgnoreCase))
        {
            exit = true;
        }
    }

    string textToWrite = $"[{DateTime.Now}] Line {lineNumber}: Writing a new line to the file.";

    // Open file with shared access
    using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.Read))
    using (StreamWriter writer = new StreamWriter(fs))
    {
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
        writer.WriteLine(textToWrite);
    }

    Console.WriteLine("Text written to file: " + textToWrite);
    lineNumber++;

    // Countdown before the next write
    for (int i = intervalMs / 1000; i > 0 && !exit; i--)
    {
        Console.Write($"Next write in {i} seconds...\r");
        Thread.Sleep(1000);
    }
    Thread.Sleep(intervalMs % 1000); // Handle remaining milliseconds
    Console.WriteLine();
}

Console.WriteLine("Exiting program.");

@RandallFlagg
Copy link
Contributor Author

RandallFlagg commented Mar 31, 2025

I'll tested it a little bit

this is version 1.12 version and your branch both have the same result 10 ms writes are impossible to handle currently, logexpert just freezes. 20 lines per 50 ms are impossible to handle currently, logexpert just freezes. 10 lines per 50 ms can be handled but i slows down considerably, but still you can use the ui. <10 lines per 50ms easily handled.

I tested it also with the version 1.9.0 and 10 ms writes are easily handled, no slowdown, regardless of how many lines (tested with +20) are written in the loaded file, so the changes done are slowing logexpert down or are not very performant.

Now I tested this with the network per your suggestion and the UI doesn't get updated. If I open it as a regular file (which is how I originally tested it) it seems to work well.

I just pushed a fix for the file:// URI. Tested with 1ms and 5000ms using your code.

Can you tell me if the behavior in the file mode (local and remote) is working as intended?

I am now going to see what the issue with SFTP is.

@Hirogen
Copy link
Collaborator

Hirogen commented Mar 31, 2025

Now I tested this with the network per your suggestion and the UI doesn't get updated. If I open it as a regular file (which is how I originally tested it) it seems to work well. Can you tell me if the behavior in the file mode is working as intended? I will check in the meantime the network issue.

not sure what you mean :D, I just opened the file and let a second program write into that file, to simulate a concurrently written logfile, and the current implementation starts to slow down when writing 20 lines per 10 ms into the opened file.

Handle local file and file:// URI.
SFTP not working.
@RandallFlagg
Copy link
Contributor Author

RandallFlagg commented Mar 31, 2025

Now I tested this with the network per your suggestion and the UI doesn't get updated. If I open it as a regular file (which is how I originally tested it) it seems to work well. Can you tell me if the behavior in the file mode is working as intended? I will check in the meantime the network issue.

not sure what you mean :D, I just opened the file and let a second program write into that file, to simulate a concurrently written logfile, and the current implementation starts to slow down when writing 20 lines per 10 ms into the opened file.

This is what I did. Tell me if you did something else:

  1. I run the test app you provided
  2. I went into log expert and opened it as a file
  3. I saw lines updating
  4. I closed the file
  5. I opened the file as a URL
  6. I saw lines updating

The fix I did today is for steps 5 and 6.
I did this test a few times, but the edges were: 1ms and 5000ms.

@Hirogen
Copy link
Collaborator

Hirogen commented Mar 31, 2025

thanks, I will test with the updated changes

@RandallFlagg
Copy link
Contributor Author

@Hirogen I get an exception when trying to open an SFTP. I get that Renci.SshNet(or something like that) is missing when trying to access SFTP. Can you check it on your system with a clean repo and tell me what I am missing? I can't seem to find it in my source dir. I can try to locate it at other places but I don't think that it is the right way to go.

@Hirogen
Copy link
Collaborator

Hirogen commented Apr 1, 2025

@Hirogen I get an exception when trying to open an SFTP. I get that Renci.SshNet(or something like that) is missing when trying to access SFTP. Can you check it on your system with a clean repo and tell me what I am missing? I can't seem to find it in my source dir. I can try to locate it at other places but I don't think that it is the right way to go.

will check in the evening

@Hirogen
Copy link
Collaborator

Hirogen commented Apr 2, 2025

Now I tested this with the network per your suggestion and the UI doesn't get updated. If I open it as a regular file (which is how I originally tested it) it seems to work well. Can you tell me if the behavior in the file mode is working as intended? I will check in the meantime the network issue.

not sure what you mean :D, I just opened the file and let a second program write into that file, to simulate a concurrently written logfile, and the current implementation starts to slow down when writing 20 lines per 10 ms into the opened file.

This is what I did. Tell me if you did something else:

  1. I run the test app you provided
  2. I went into log expert and opened it as a file
  3. I saw lines updating
  4. I closed the file
  5. I opened the file as a URL
  6. I saw lines updating

The fix I did today is for steps 5 and 6. I did this test a few times, but the edges were: 1ms and 5000ms.

I tested it again, the problem starts occuring when you open the filter dialog and try to filter the file thats currently written, then the UI starts to freeze, until then, it was not a problem, only after I opened the filter dialog.

Frozen:
image

As long as the dialog is closed, the UI is fine. So something with the filter dialog is at play.

Also I was running that on my Home PC, on an M2, so it's definitely not an I/O problem of the file system, but rather an update / UI problem. Maybe someting in the LogEventWorker function, in LogWindowPrivate.cs since I got an ObjectDisposedException there, when I closed Logexpert, so it seems the UpdateGrid delegate is slower, or something in there.

image With about 2.5 million lines, the UI is unresponsive

Currently checking also the SFTP Problem you mentioned

@Hirogen
Copy link
Collaborator

Hirogen commented Apr 2, 2025

@Hirogen I get an exception when trying to open an SFTP. I get that Renci.SshNet(or something like that) is missing when trying to access SFTP. Can you check it on your system with a clean repo and tell me what I am missing? I can't seem to find it in my source dir. I can try to locate it at other places but I don't think that it is the right way to go.

I dont get that error, everything is fine with me, have you cleared bin / obj folders?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants