简体   繁体   English

数据库中ASP.NET页面内容与文件性能的关系?

[英]ASP.NET page content in database vs file performance?

I am creating a site whose content is dynamic and has images in it. 我正在创建一个网站,其内容是动态的并且包含图像。 What/How much performance hit will my DB (MSSQL) take if I save content/Images in DB? 如果将内容/图像保存在数据库中,数据库(MSSQL)将对性能产生什么影响?

I am just trying to understand what kind of problems I may run into. 我只是想了解我可能遇到的问题。 I appreciate any responses. 感谢您的回应。

Thanks! 谢谢!

If you keep content (eg images) outside of the database, you can let IIS serve this content directly without calling ASP.NET at all (and as a consequence, no database access is needed). 如果将内容(例如图像)保留在数据库之外,则可以让IIS直接提供此内容而无需调用ASP.NET(因此,不需要数据库访问)。

You can even put static content on a different server is you have huge load (like here on StackOverflow). 如果负载很大,您甚至可以将静态内容放在其他服务器上(例如此处的StackOverflow)。

So if you need to scale in any way, keep static content outside of both ASP.NET and database. 因此,如果您需要以任何方式扩展,请将静态内容保留在ASP.NET和数据库之外。

In the company where I'm employed we are using a custom-made CMS. 在我受雇的公司中,我们使用定制的CMS。
It renders content and controls for a page dynamically. 它动态呈现页面的内容和控件。 The content are stored in a table for all pages, (each page has one main content), and other tables store information regarding UserControls, path to it, and which properties should be set with which value via reflection. 内容存储在所有页面的表中(每个页面都有一个主要内容),其他表存储有关UserControls的信息,指向它的路径以及应该通过反射将哪个属性设置为哪个值。
The performance is good, even for lets say 10 dynamically created controls. 即使对于说10个动态创建的控件,性能也很好。 Our biggest client's page has about 70k hits a day and there is no performance problem. 我们最大的客户页面每天有大约7万次点击,并且没有性能问题。 The page renders really fast. 该页面呈现速度非常快。

Storing the images in your database can also work. 将图像存储在数据库中也可以。
Just keep in mind that you need to use server-side caching for your images (eg get them via a generic handler *.ashx and use chaching there) and hope that your imageurl gets recognized for clientside caching. 只需记住,您需要为图像使用服务器端缓存(例如,通过通用处理程序* .ashx获取它们并在其中使用缓存),并希望您的imageurl能被客户端缓存识别。
If you want to be sure, expose your images directly on a dedicated image application. 如果要确定,请直接在专用图像应用程序上公开图像。 (eg www.foobar.com is your URL, then you can create images.foobar.com and store all your images there) (例如,www.foobar.com是您的URL,那么您可以创建images.foobar.com并将所有图像存储在那里)

If would definetly advise to store often used images there, like images for the layout, or userpictures (if you are using a forum, or some kind of web application that uses several pictures all the time). 如果明确建议在此处存储常用的图像,例如用于布局的图像或用户图片(如果您使用的是论坛或始终使用多张图片的某种Web应用程序)。 But there is nothing wrong with storing not often used pictures in the database (user related uploads et cetera). 但是将不经常使用的图片存储在数据库中并没有错(与用户相关的上传等)。

If you store your images in DB, database size will increase and this will result in slower DB queries. 如果将图像存储在数据库中,数据库大小将增加,这将导致数据库查询变慢。 Better store on other media and guide your DB to do the stuff for you. 更好地存储在其他介质上,并指导您的数据库为您完成这些工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM