在生产 MVC/SQL 应用程序中记录大量操作
我们是 ASP.NET MVC 框架和 SQL Server 的满意用户,目前正在使用 LINQ-to-SQL。它通过面向消费者的应用程序很好地满足了我们的需求,该应用程序拥有约 140 万用户和每月超过 200 万的活跃独立用户。
我们早就应该开始记录所有用户操作(文章的浏览、我们网站上的搜索等),并且我们正在尝试寻找合适的架构来执行此操作。
我们希望归档系统成为其自己的实体,而不是存储生产文章和搜索引擎的主 SQL 集群的一部分。我们希望它成为自己的 SQL 集群,一开始只有一个盒子。
为了简化问题,假设我们只想记录这数百万用户当月进入我们网站的搜索词,并且我们希望以尽可能最少的周期密集方式来执行此操作。
我的问题: (1) 是否有异步方式将搜索词转储到远程盒子? LINQ 是否支持异步?
(2) 您是否建议在 RAM 缓存中建立一个包含 1,000 个(userId、searchTerm、date)日志项的缓存,然后定期将它们刷新到数据库中?我认为这种方法会减少打开/关闭连接。
或者我的想法完全错误?我们希望在易于实施和稳健性之间取得平衡。
We are happy users of the ASP.NET MVC framework and SQL Server, currently using LINQ-to-SQL. It serves our needs well with a consumer-facing application with about 1.4 million users and 2+ million active uniques per month.
We are long overdue to start logging all user actions (views of articles, searches on our site, etc.) and we're trying to scope out the right architecture to do so.
We'd like the archiving system to be its own entity, and not part of the main SQL cluster that stores the production articles and search engine. We'd like it to be its own SQL cluster, starting out with just one box initially.
To simplify the problem, let's say we just want to log the search terms that these millions of users enter into our site for the month, and we want to do so in the least cycle-intensive-way possible.
My questions:
(1) Is there an asynchronous way to dump the search terms to a remote box? Does LINQ support async for this?
(2) Would you recommend building up a cache of say 1,000 (userId, searchTerm, date) logging items in a RAM cache, and then flushing those at intervals to the database? I assume this method would cut down on open/close connections.
Or am I thinking about this entirely wrong? We'd like to strike a balance between ease of implementation and robustness.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1)当然可以,有不同的解决方案来实现它。 Linq 不是您需要的工具。
2)这样做应该不会有任何重大改进,只有在执行搜索时才会触发“日志记录”。您最终会接到两个电话,而不是一个,没什么大不了的。
建议使用 AOP
您可以使用 Postsharp (不过还有其他选择)。然后,仅当您需要跟踪传递给操作的内容时,您才可以使用所需的日志记录属性来装饰您的操作。
这种方法的主要优点是:
AOP 的常见做法,特别是当涉及到可以添加到多个方法的行为时,例如日志记录、身份验证等。是的,它可以以异步方式使用。
1)Sure you can, there are different solution to achieve it. Linq is not the instrument you need.
2)There should not be any major improvement by doing it, the "logging" will be triggered only when a search is performed. You will end up with two calls instead of one, not a big deal.
A suggestion is to use AOP
You can create a clean and separate layer for logging using Postsharp (there are other alternatives though). You will then decorate your actions with the required logging attribute only when you need to trace what is passed to the action.
Main advantages with this approch are :
AOP is a common practice specially when it comes to behavior that can be added to more than one method, like logging, authentication and so on. And yes it can be used in an async way.
1)我建议您创建一个
HttpModule
来“捕获”用户使用的所有搜索词。如何以及在何处转储这些信息(您说过您将使用 SQL 框)是另一回事,这超出了模块的范围,该模块应该只捕获搜索项。然后,您可以创建一个包含登录名的组件,以使用异步调用存储这些信息(甚至是像 Log4Net 这样的第三方组件)
2)如果您想创建一种批量插入缓存您需要存储的所有信息,并且在某个时刻将它们转储到 SQL 上我会使用 MSMQ 或任何其他支持可靠性的技术:我认为您希望在系统崩溃等情况下释放所有这些信息
1)I would suggest you to create an
HttpModule
that "catch" all the search terms used by the users. How and where you will dump those information(you said you will use a SQL box) it's another matter which is outside the scope of the module which should just catch the Search tems.Then you can create a component that contains the login to store those information using Async call(or even a third part component like Log4Net )
2) if you want create a kind of batch insert caching all the information you need to store and at some point dump them on SQL I would use
MSMQ
or any other technology that support theReliability
: I think you want loose all those information in the case of a system-crash,etc