SQL Server Job with precise timing

允我心安 提交于 2019-12-11 04:45:24

问题


I have a DB with game data (map, players, etc...) and I have a game core mechanics written in T-SQL stored procedure.

I need process game loop (via the stored procedure) every "X" seconds.

I tried used the SQL Job, but when I set the interval to seconds, the SQL server stops responding. If I set the interval greater than one minute, all was ok.

I need game loop precise in time, e.g. the game loop will run only once and will be executed every "X" precisely (tolerance should be less than one second).

Can I do it with SQL Server capabilities? Or should I create a windows service which will repeatly execute game loop procedure? Or should I go another way?

Thanks!

EDIT:

The game loop stored procedure takes less than the interval.


回答1:


I would use a windows service for this. Have a loop with a thread sleep in it to get it to wait every x seconds.

The problem with timer jobs of type used in SQL server, is that there is a timer service checking if there is a job that need to be run. This timer job may check for example every 2 minutes, so precision down to a second is not possible.




回答2:


To run smth with interval of 1 sec you can use code:

CREATE PROCEDURE SP_Execute_job 
AS 
    WHILE 1=1
    BEGIN
     WAITFOR DELAY '00:00:01'
     EXECUTE 'somewhat job'
    END
END

This sp should be executed after each SQL Server start:

exec sp_procoption N'SP_Execute_job', 'startup', 'on'


来源:https://stackoverflow.com/questions/2809442/sql-server-job-with-precise-timing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!