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 re开发者_运维问答peatly execute game loop procedure? Or should I go another way?
Thanks!
EDIT:
The game loop stored procedure takes less than the interval.
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.
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'
精彩评论