查看数据填充的最佳实践?

时间:2023-01-20 22:49:11

I've been working on a .NET application and experiencing a memory error (I'm a java developer that can do other things), I've been thinking about performance. What I'm posting about was not the memory problem. The memory problem just started me thinking.

我一直在研究.NET应用程序并遇到内存错误(我是一个可以做其他事情的java开发人员),我一直在考虑性能。我发布的内容不是内存问题。记忆问题刚开始让我思考。

I've repeated a trend in my ASP.NET application that I've used on countless J2EE applications: using Business Entities to populate drop down lists. The more I think about it, the more I don't like it. For example, on the app I'm working we have a drop down list of current projects. A project is a graph of objects. However, to create the list we pull back all of the projects, create the graph and only use the id and display name. This seems to be a terrible waste. To be fair, the dal layer is entirely hand written. The lead architect would not allow an ORM like NHibernate.

我在我的ASP.NET应用程序中重复了一个我在无数J2EE应用程序中使用的趋势:使用Business Entities填充下拉列表。我想的越多,我就越不喜欢它。例如,在我正在运行的应用程序上,我们有一个当前项目的下拉列表。项目是对象图。但是,要创建列表,我们将撤回所有项目,创建图形并仅使用id和显示名称。这似乎是一种可怕的浪费。公平地说,dal层完全是手写的。首席架构师不允许像NHibernate这样的ORM。

I realize that all of these objects are in GEN0 and quickly garbage collected. What worries me is that I'm taxing the GC. Ever 5% of the CPU needed to process the GC is 5% of CPU I can't use else where. This site is one of the few that I really respect. What do you all think? Is it bad to use the entity model for this? Should I create a set of IdValue objects that only house the display value and id? Would creating such a view object tier (I don't suppose this will go in the business layer) just create redundant code?

我意识到所有这些对象都在GEN0中并且很快被垃圾收集。令我担心的是,我对GC征税。处理GC所需的CPU总量的5%是CPU的5%,我不能在其他地方使用。这个网站是我真正尊重的少数网站之一。你们都在想什么?为此使用实体模型是不是很糟糕?我应该创建一组仅容纳显示值和id的IdValue对象吗?创建这样的视图对象层(我不认为这将进入业务层)只是创建冗余代码?

Thanks, JPD

3 个解决方案

#1


I've been working on line of business .NET apps for the last few years and have yet to run into a performance problem that was resolved by trying to help the garbage collector work more efficiently.

在过去的几年里,我一直在研究业务线.NET应用程序,并且尚未遇到通过尝试帮助垃圾收集器更有效地工作而解决的性能问题。

Gathering metrics on the otherhand has been incredibly helpful for to improve performance, memory usage, etc.

另一方面收集指标对于提高性能,内存使用等非常有帮助。

#2


Don't worry about taxing the GC, it will tune itself to your application to give you optimal performance. Yes it is best to reduce your memory footprint but I don't think it is quite as serious a problem as you imagine.

不要担心对GC征税,它会根据您的应用程序调整自己以获得最佳性能。是的,最好减少你的内存占用,但我不认为这是一个像你想象的那么严重的问题。

A good DAL that allows you to return only the data that you need will increase the performance of your application and will also decrease the amount of memory required by your application. But whether you use "too much" memory or not, I imagine that in most cases the GC will be able to handle it just fine.

一个好的DAL允许您只返回所需的数据,这将提高应用程序的性能,还会减少应用程序所需的内存量。但是不管你是否使用“太多”内存,我想在大多数情况下GC都可以很好地处理它。

#3


An alternative approach is to create light-weight objects for your purposes. In this instance you would have a lighweight project object with only the id and display name. The decision then needs to be made over re-using the existing DAL or creating a lightweight version of the DAL.

另一种方法是为您的目的创建轻量级物体。在这种情况下,您将拥有一个只有id和显示名称的轻量级项目对象。然后需要重新使用现有DAL或创建轻量级DAL。

#1


I've been working on line of business .NET apps for the last few years and have yet to run into a performance problem that was resolved by trying to help the garbage collector work more efficiently.

在过去的几年里,我一直在研究业务线.NET应用程序,并且尚未遇到通过尝试帮助垃圾收集器更有效地工作而解决的性能问题。

Gathering metrics on the otherhand has been incredibly helpful for to improve performance, memory usage, etc.

另一方面收集指标对于提高性能,内存使用等非常有帮助。

#2


Don't worry about taxing the GC, it will tune itself to your application to give you optimal performance. Yes it is best to reduce your memory footprint but I don't think it is quite as serious a problem as you imagine.

不要担心对GC征税,它会根据您的应用程序调整自己以获得最佳性能。是的,最好减少你的内存占用,但我不认为这是一个像你想象的那么严重的问题。

A good DAL that allows you to return only the data that you need will increase the performance of your application and will also decrease the amount of memory required by your application. But whether you use "too much" memory or not, I imagine that in most cases the GC will be able to handle it just fine.

一个好的DAL允许您只返回所需的数据,这将提高应用程序的性能,还会减少应用程序所需的内存量。但是不管你是否使用“太多”内存,我想在大多数情况下GC都可以很好地处理它。

#3


An alternative approach is to create light-weight objects for your purposes. In this instance you would have a lighweight project object with only the id and display name. The decision then needs to be made over re-using the existing DAL or creating a lightweight version of the DAL.

另一种方法是为您的目的创建轻量级物体。在这种情况下,您将拥有一个只有id和显示名称的轻量级项目对象。然后需要重新使用现有DAL或创建轻量级DAL。