我被分配实现一个包装类来在非托管C ++中使用ADO管理数据库连接,然后构建一个如下工作的应用程序: 我会有3个(或者更多)应用程序作为服务运行的实例,每个实例必须检查数据库中每个2s是否存在任何未决的子目录(待处理的子目录是程序子项[给定问题的解决方案]等待评估),如果存在,我得到并评估它,然后我更新该子设置设置结果并从挂起表中删除它。(评估子指令的范围时间是:0s> range<〜(5-10)s和一个实例永远不会同时评估更多的一个submition)。 我的问题是: 我有两种可能的解决方案: 一旦我实例化应用程序并且从不关闭它就建立连接(当我删除实例时关闭它,理论上永远不会发生。)或者每2秒打开一个连接以获得pe nding submition(如果存在的话)并关闭它,然后重新打开它以更新submition并再次关闭.... 什么解决方案更好,为什么?
I was assigned to implement a wrapper class to manage DB connections using ADO in unmanaged C++ and then build an application that works as follow: "I'll have 3 (or maybe more) instances of the application running as a service, each instance has to check if exists any pending submition in the DB each 2s (a pending submition is a program submition [a solution to a given problem] waiting for evaluation), if exists I get and evaluate it, then I update that submition setting the results and deleting it from the pending table. (the range time to evaluate a submition is: 0s > range < ~(5-10)s and an instance never evaluate more that one submition at the same time)." My problem is: I have 2 possibles solutions here: Stablish a connection once I instanciate the application and never close it (close it when I delete the instance, that theorically never will happen.) or open a connection each 2s in order to get the pending submition (if exists any) and close it, then re-open it to update the submition and close it again.... What solution is better and why?
推荐答案这取决于您的实时延迟。我会使用一个打开的连接,但是你需要一些错误的后备。 您应该考虑更大的间隔而不是打开和关闭连接。 所有2秒24小时和每周7天??? 你和你的用户真的需要这样吗?小间隔? It depends on your real time latencies. I would use one open connection, but you need some fallback for the errorcase. You should consider bigger intervals and than open and close the connection. All 2 seconds and 24 hours and that 7 days a week??? Do you AND your user REALLY need such small intervals?
更多推荐
长期连接或按需连接?
发布评论