GithubHelp home page GithubHelp logo

work() cpu 100% about php-cron-scheduler HOT 2 CLOSED

okool avatar okool commented on June 8, 2024
work() cpu 100%

from php-cron-scheduler.

Comments (2)

peppeocchi avatar peppeocchi commented on June 8, 2024

It's a good suggestion but it might miss runs.
This is not intended for a production environment, but only for testing the scheduler is working.

What I mean by missing runs is easy to explain. Your version will sleep for 1 second on every loop, but there is also some overhead on running those 4 lines of code, so your entire execution will take 1 second and 50 milliseconds. In the long run all those milliseconds add up to a second, so let's say your next loop enters at 00:00:59.980. then you sleep for 1 second plus the overhead of 50 milliseconds, the next run will be at 00:01:01.030. If you want it to run at second 0, that run will be missed, because on the previous run date('s') = 59, on the current run date('s') = 1.

A more optimised (?) version might be to usleep for the amount of ms left in your second.
If you want to do it, please fell free to create a PR, thanks

from php-cron-scheduler.

cuchac avatar cuchac commented on June 8, 2024

Hello,
we currently face the same issue. We had to reimplement the work loop in our application, because we just called work() from the library and did not care about implementation and we were surprised to discover 100% CPU load.

Would you accept PR implementing following logic?

  1. Find earliest schedule date from all jobs
  2. Sleep using usleep() exact number of ms
  3. $this->run();
  4. Repeat

from php-cron-scheduler.

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.