I am in the process of implementing several tagging fields on my website that include an autocomplete option using the jquery UI plugin. I have everything working, and while the widget itself isn't as robust as I would prefer (is there a way to make the first item in the list always highlighted, for instance), it is serviceable for now.
我正在我的网站上实现几个标记字段,包括使用jquery UI插件的自动完成选项。我有一切正常工作,虽然小部件本身并不像我希望的那样健壮(例如,有没有办法让列表中的第一个项目突出显示),但它现在可以使用。
My question is around handling the server-side requests for the autocomplete data. Right now I'm using AJAX to retrieve the potential matches for the supplied input term. The table I'm hitting has around 10,000 records in it, and my thought was that rather than constantly querying that table, I could just cache a list of those records in a shared/static property on my server (I'm using ASP.NET MVC with a SQL Server backend by the way) and query that list instead. I would refresh the list every 4 hours or so, just to keep it up to date.
我的问题是处理服务器端对自动完成数据的请求。现在我正在使用AJAX来检索所提供输入术语的潜在匹配。我正在点击的表中有大约10,000条记录,而我的想法是,我可以只在服务器上的共享/静态属性中缓存这些记录的列表(我正在使用ASP)。 NET MVC与SQL Server后端的方式)并查询该列表。我会每隔4个小时更新一次清单,只是为了让它保持最新状态。
The idea is obviously to reduce the strain on my SQL server and maximize the performance of the autocomplete drop down. What I'm ultimately wondering is if it's bad practice to keep a list/array of 10,000 values in memory on my server; is there a known limit/threshold here? My server has 2GB of RAM, and may need to be upgraded soon anyway.
这个想法显然是为了减轻我的SQL服务器的压力,并最大限度地提高自动完成下拉的性能。我最终想知道的是,在我的服务器上保留10,000个值的列表/数组是不好的做法;这里有一个已知的限制/阈值吗?我的服务器有2GB的RAM,无论如何都可能需要很快升级。
Any suggestions would be much appreciated.
任何建议将不胜感激。
Thanks for your time!
谢谢你的时间!
2 个解决方案
#1
2
10,000 small strings shouldn't be too bad - I've done that before with no noticeable side effects.
10,000个小字符串不应该太糟糕 - 我之前没有明显的副作用。
I would recommend running your app without the items in memory, and then again with, and take a look at memory and CPU usage in Task Manager in Windows, just to get an idea of how much memory you truly are using up - that will help determine if it will cause problems down the road.
我建议在没有内存中的项目的情况下运行您的应用程序,然后再次使用,并查看Windows中任务管理器中的内存和CPU使用情况,只是为了了解您真正耗尽了多少内存 - 这将有所帮助确定它是否会导致问题。
But hitting the database each time probably wouldn't be that bad either - unless you hae a ton of traffic, the effect would likely be negligible.
但每次击中数据库可能也不会那么糟糕 - 除非你有大量的流量,效果可能会微不足道。
#2
2
Why dont you use the OutputCache attribute provided by asp.net mvc. Its better than storing them in memory, just let the framework handle it for you.
为什么不使用asp.net mvc提供的OutputCache属性。它比将它们存储在内存中更好,只需让框架为您处理它。
You can easily set your timeout, etc.
您可以轻松设置超时等。
#1
2
10,000 small strings shouldn't be too bad - I've done that before with no noticeable side effects.
10,000个小字符串不应该太糟糕 - 我之前没有明显的副作用。
I would recommend running your app without the items in memory, and then again with, and take a look at memory and CPU usage in Task Manager in Windows, just to get an idea of how much memory you truly are using up - that will help determine if it will cause problems down the road.
我建议在没有内存中的项目的情况下运行您的应用程序,然后再次使用,并查看Windows中任务管理器中的内存和CPU使用情况,只是为了了解您真正耗尽了多少内存 - 这将有所帮助确定它是否会导致问题。
But hitting the database each time probably wouldn't be that bad either - unless you hae a ton of traffic, the effect would likely be negligible.
但每次击中数据库可能也不会那么糟糕 - 除非你有大量的流量,效果可能会微不足道。
#2
2
Why dont you use the OutputCache attribute provided by asp.net mvc. Its better than storing them in memory, just let the framework handle it for you.
为什么不使用asp.net mvc提供的OutputCache属性。它比将它们存储在内存中更好,只需让框架为您处理它。
You can easily set your timeout, etc.
您可以轻松设置超时等。