设置 HTTPHandler isreusable 属性
我正在使用 HTTP 处理程序来引发文件下载。“ProcessRequest”中的代码基本上从数据库检索数据,创建现有模板电子表格的临时副本,并以 GUID 作为名称,并将从数据库检索到的数据写入单元格中通过使用 COM 的单元格,引发文件下载并删除创建的临时电子表格。整个过程通常需要大约 4-5 分钟。但是当我们尝试同时测试此过程时,大约需要 15 分钟。
我想知道将“IsReusable”布尔值设置为 true 是否有助于提高性能。但我不确定它是否安全。
有人可以帮我吗?
**更新:**因为我为创建的每个临时文件使用不同的文件名,所以我假设不会出现安全问题。但仍不确定。
I am using a HTTP handler to raise a file download.Basically code in the 'ProcessRequest' retrieves data from the database,creates a temporary copy of the existing template spreadsheet with a GUID as its name and writes data retrieved from the DB into it cell by cell using COM,raises a file download and deletes the temporary spreadsheet created.This whole process usually takes around 4-5 mins.But when we tried to concurrently test this process it took around 15 mins.
I am wondering if setting 'IsReusable' boolean to true could help improving the performance.But I am not sure,if it is safe.
Could someone please help me with it?
**Update:**Because I am using a different filename for each of the temporary files created I am assuming that there wont be safety issues.But still not sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IsReusable
属性将按照您的想法进行操作。它将重用现有的处理程序,而不是每次发出请求时都构建一个全新的处理程序来使用。如果您在构造函数中创建了实例变量,则可以提高性能,但前提是创建它们的成本很高。另外,如果您在处理程序中维护任何类型的状态,那么您将其保留的任何状态都将在下一个请求中出现。这可能会产生意想不到的副作用。
如果您的大部分流程发生在
ProcessRequest
方法中,那么您的瓶颈就在那里,您应该使用分析来查看可以在哪里提高性能。The
IsReusable
property will do just what you think it does. Instead of constructing a brand new Handler to be used each time a request is made, it will reuse the existing one. If you have instance variables that are created in the constructor it could boost performance, but only if they are expensive to create.Also, if you are maintaining any kind of state in the handler, then whatever state you leave it in will be there for the next request. This could have unintended side effects.
If the bulk of your process happens in the
ProcessRequest
method, then your bottle-neck is there, and you should use profiling to see where you can speed up performance.仅当 HttpHandler 的实例需要处理多个请求时,IsReusable 属性才设置为 true。可能有不同的 Web.Config 设置可以解决您的问题,可能是 httpRuntime 属性的executionTimeout 属性:
更多信息:
http://articles.sitepoint.com/article/web-config-file-demystified
The IsReusable property is only set to true if this instance of the HttpHandler is expected to handle multiple requests. There may a different Web.Config setting that addresses your issue, perhaps the executionTimeout attribute of the httpRuntime property:
More info:
http://articles.sitepoint.com/article/web-config-file-demystified