Coder Social home page Coder Social logo

Comments (8)

lahma avatar lahma commented on May 24, 2024 1

The problem here is that DailyCalendar.GetNextIncludedTimeUtc() iterates checking every next millisecond whether it would fit the range. Increments could be larger / start position could be calculated more precisely when we know that there's no need for millisecond or even second precision.

from quartznet.

al007 avatar al007 commented on May 24, 2024

The following calendar configuration crashes on GetNextIncludedTimeUtc: System.ArgumentOutOfRangeException : The UTC time represented when the offset is applied must be between year 0 and 10,000. (Parameter 'offset')

    [Test]
    public void GetNextIncludedTimeUtc()
    {
        TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

        var weeklyCalendar = new WeeklyCalendar()
        {
            TimeZone = timeZone,
        };

        var dailyCalendar = new DailyCalendar(weeklyCalendar, "06:00", "22:00")
        {
            TimeZone = timeZone,
            InvertTimeRange = true,
        };

        var holidayCalendar = new HolidayCalendar(dailyCalendar)
        {
            TimeZone = timeZone,
        };
        holidayCalendar.AddExcludedDate(new DateTime(2024, 2, 19));
        holidayCalendar.AddExcludedDate(new DateTime(2024, 5, 27));
        holidayCalendar.AddExcludedDate(new DateTime(2024, 6, 19));
        holidayCalendar.AddExcludedDate(new DateTime(2024, 7, 4));
        holidayCalendar.AddExcludedDate(new DateTime(2024, 9, 2));
        holidayCalendar.AddExcludedDate(new DateTime(2024, 10, 14));
        holidayCalendar.AddExcludedDate(new DateTime(2024, 11, 11));
        holidayCalendar.AddExcludedDate(new DateTime(2024, 11, 28));
        holidayCalendar.AddExcludedDate(new DateTime(2024, 12, 25));

        var time = new DateTime(2024, 2, 5, 10, 6, 0, DateTimeKind.Utc);
        var expected = new DateTime(2024, 2, 5, 14, 0, 0, DateTimeKind.Utc);

        var d = holidayCalendar.GetNextIncludedTimeUtc(time); // throws System.ArgumentOutOfRangeException : The UTC time represented when the offset is applied must be between year 0 and 10,000. (Parameter 'offset')
        d.Should().Be(expected);
    }

from quartznet.

jafin avatar jafin commented on May 24, 2024

Possibly related dotnet/runtime#25075
One hotspot is the calls to TimeZoneInfo.ConvertTime in a tight loop.

image

from quartznet.

jafin avatar jafin commented on May 24, 2024

@al007 Please check if latest 3.x / master branches in repo resolves your issue.

from quartznet.

al007 avatar al007 commented on May 24, 2024

No, unfortunately, it does not. The example from the 1st post in this thread works even slower now: 20 seconds for .net8 and 50 seconds for net472. However, it does fix the crash for the 2nd example.

from quartznet.

jafin avatar jafin commented on May 24, 2024

The example you provided should be in the repo, it executes here in about 43ms.
This is from 3.x branch.

Can you please try running.?

dotnet test --filter GetNextIncludedTimeUtc_CrashOriginal2270
Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: 43 ms - Quartz.Tests.Unit.dll (net8.0)

from quartznet.

al007 avatar al007 commented on May 24, 2024

@jafin , this method has two issues: poor performance and a crash. I reported them together because I thought they were related and re-working the algorithm would fix both.

Performance issue happens for the following calendar configuration HolidayCalendar->WeeklyCalendar->DailyCalendar, see 1st post here. It is not fixed in the 3.x branch. It takes from 20 to 50 seconds as described above.

The crash happens for calendar WeeklyCalendar->DailyCalendar->HolidayCalendar, see 2nd post here. It is fixed in the 3.x branch and runs fast.

from quartznet.

jafin avatar jafin commented on May 24, 2024

@al007 Perhaps I am missing something I copied the example, ran the below against 3.x branch, completed in ~20ms

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: 11 ms - Quartz.Tests.Unit.dll (net8.0)
Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: 22 ms - Quartz.Tests.Unit.dll (net472)
[Test]
public void GetNextIncludedTimeUtcFirstIssue()
{
    TimeZoneInfo timeZone = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

    var holidayCalendar = new HolidayCalendar()
    {
        TimeZone = timeZone,
    };
    holidayCalendar.AddExcludedDate(new DateTime(2024, 2, 19));
    holidayCalendar.AddExcludedDate(new DateTime(2024, 5, 27));
    holidayCalendar.AddExcludedDate(new DateTime(2024, 6, 19));
    holidayCalendar.AddExcludedDate(new DateTime(2024, 7, 4));
    holidayCalendar.AddExcludedDate(new DateTime(2024, 9, 2));
    holidayCalendar.AddExcludedDate(new DateTime(2024, 10, 14));
    holidayCalendar.AddExcludedDate(new DateTime(2024, 11, 11));
    holidayCalendar.AddExcludedDate(new DateTime(2024, 11, 28));
    holidayCalendar.AddExcludedDate(new DateTime(2024, 12, 25));

    var weeklyCalendar = new WeeklyCalendar(holidayCalendar)
    {
        TimeZone = timeZone,
    };
    var calendar = new DailyCalendar(weeklyCalendar, "06:00", "22:00")
    {
        TimeZone = timeZone,
        InvertTimeRange = true,
    };
    var time = new DateTime(2024, 2, 5, 10, 6, 0, DateTimeKind.Utc);
    var expected = new DateTime(2024, 2, 5, 14, 0, 0, DateTimeKind.Utc);

    var d = calendar.GetNextIncludedTimeUtc(time); // takes 13 seconds to execute!
    d.Should().Be(expected);
}

from quartznet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.