我应该在哈希映射中保存数据库表以加速我的程序
我有一个访问设备的轮询循环,一些设备链接在一起,因此当轮询其中一个链接设备时,必须将其状态复制到另一个链接设备。
我正在尝试加快更新第二个链接设备的过程。如果设备 4 链接到设备 5,则速度很快,但如果轮询设备 5 并且发现更改,则必须等到轮询循环完成并再次启动。
我的想法是作为民意调查的一部分检查设备是否已链接,以便可以立即更新。有关链接哪些设备的信息存储在数据库中,并且每次轮询都调用数据库会大大减慢系统速度,我认为所以我想做的是创建该表的哈希表并检查它。
所以这是我的问题
这个想法行得通吗?
哈希表会比数据库检查更快吗?
我应该多久重新创建一次哈希表,程序将一次运行几周?
这是最好的方法吗?还有其他方法可以加快轮询循环吗?
I have a polling loop that accesses devices, some of the devices are linked together and as such when one of the linked devices is polled its state must be copied to the other linked device.
I am trying to speed up the process of updating the second linked device. if device 4 is linked to device 5 it is fast but if device 5 is polled and a change found it has to wait till the polling loop is completed and started again.
My idea is to check as part of the poll if the device is linked so it can be updated immediately. The information on what devices are linked is stored in the database and making a call to the database for every poll will slow down the system dramatically I think so what I wanted to do was create a hash table of the table and check that instead.
so here are my questions
would this idea work ?
would the hash table be faster than the database checks ?
how often should I recreate the hash table, the program will run for weeks at a time ?
is this the best way of doing this. are there other ways to speed up a polling loop ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果优先考虑搜索,请使用哈希表。哈希表在按键搜索时提供非常快速的搜索机制,在按值搜索时提供相当好的搜索机制
如果您希望能够删除特定元素,请使用哈希表(使用Remove方法)
当元素的存储顺序与您无关时,请使用哈希表。
如果您需要按某种特定顺序排列元素,请不要使用哈希表。您不能依赖哈希表如何对其元素进行排序
如果需要在特定位置插入元素,请勿使用哈希表
如果要存储具有相同值的多个键,请勿使用哈希表。哈希表中的所有键都必须是唯一的。
Use a hash table if searching is a priority. Hash tables provide very quick search mechanisms when searching by key, and fairly good searching when searching by value
Use a hash table if you want to be able to remove specific elements (use the Remove method)
Use a hash table when the order the elements is stored is irrelevant to you.
Don't use a hash table if you need the elements in some specific order. You cannot rely on how a Hashtable will sort its elements
Don't use a hash table if you need to insert an element in a particular location
Don't use a hash table if you want to store multiple keys with the same value. All keys inside a hash table must be unique.