具有精确定时的 SQL Server 作业
我有一个包含游戏数据(地图、玩家等)的数据库,并且有一个用 T-SQL 存储过程编写的游戏核心机制。
我需要每“X”秒处理一次游戏循环(通过存储过程)。
我尝试使用 SQL 作业,但是当我将间隔设置为秒时,SQL 服务器停止响应。如果我将间隔设置为大于一分钟,则一切正常。
我需要及时精确的游戏循环,例如游戏循环将仅运行一次,并且将精确地在每个“X”执行(容差应小于一秒)。
我可以使用 SQL Server 功能来做到这一点吗?或者我应该创建一个Windows服务来重复执行游戏循环程序?或者我应该走另一条路?
谢谢!
编辑:
游戏循环存储过程花费的时间小于间隔。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会为此使用 Windows 服务。有一个循环,其中有一个线程休眠,让它每 x 秒等待一次。
SQL Server 中使用的计时器作业类型的问题在于,有一个计时器服务检查是否有需要运行的作业。该计时器作业可能会检查一次,例如每 2 分钟检查一次,因此不可能精确到一秒。
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.
要以 1 秒的间隔运行 smth,您可以使用代码:
应在每次 SQL Server 启动后执行此 sp:
To run smth with interval of 1 sec you can use code:
This sp should be executed after each SQL Server start: