Cron jobs over 100 per minute, too many?

2019-09-14 00:12发布

问题:

Hello I have a server with 100 client sites, each with its own database. I need each one to run a cron job every minutes 24/7 to check to see if the client has set a post to publish at that time, if so set is_published to 1 in the post table. My question is, without benchmark testing available, is 100 cron jobs every minute going to slow down my server significantly? I know this is vague, but I am running a Linux server with 1024MB of ram on a 10MBps port.

回答1:

Yes, this is a bad idea, for a number of reasons. Load on the server is one of them. Do you really want to invest your hardware dollars in setting the flag is_published in hundreds of databases? Do clients care about the up-to-one minute lag? What happens if the number of clients grows more quickly than you expect?

There is an easier way. Just have a column with PostedTime in the posts table. Then create a view that uses this column:

create view v_posts as
    select p.*, (PostedTime >= now()) as is_published
    from posts;


回答2:

It just a bit more that 1 request per second. If the cron jobs are distributed evenly within that minute, and if the cron job is really simple and fast, I can't see where the problem could be.



标签: mysql linux cron