当我们开发人员编写数据访问代码时,如果应用程序应该很好地扩展并处理负载/点击,我们真正应该担心什么。
考虑到这个简单的问题,您将如何以可扩展的方式解决它。
1.ProjectResource
是一个类(封装分配给Project
的资源)
2.分配给Project的每个资源都是User
类
3.每个Project
中的 >User 还具有 ReportingHead
和 ProjectManager
,它们也是 User
4 的实例。最后有一个包含项目详细信息的 Project
类
使用的类图例
User
Project
ProjectResource
表图
ProjectResource< /p>
资源 ID
项目ID
用户 ID
报告负责人
项目经理
类图
ProjectResource
ResourceId:字符串/Guid
项目:项目
用户:用户
报告负责人:用户
项目经理:用户
注意:
所有用户信息都存储在 User 表中
所有 Project 信息存储在项目表中
问题如下:
当应用程序请求项目中的资源时,遵循以下操作
首先获取项目的记录
获取UserId,发出请求(使用Users DAL
)来获取用户实例
获取ProjectId,制作请求(使用Projects DAL
)获取项目信息
最后将Users
和Project
分配给ProjectResource
的实例
显然你可以请参阅此处进行的 3 Db Calls
用于填充单个 ProjectResource
,但问题以及管理对象的人员已明确定义。 这是我计划的方式,因为 Sql Server
中还提供连接池
ADO.net
还有另一种方法,即使用表内部联接然后填充来一次检索所有详细信息。
我到底应该走哪条路,为什么?
附加功能:
.NET 2.0、ASP.net 2.0、C#、Sql Server 2005、托管应用程序的同一台计算机上的 DB。
When we developers write data access code what should we really worry about if the application should scale well and handle the load / Hits.
Given this simple problem , how would you solve it in scalable manner.
1.ProjectResource
is a Class ( Encapsulating resources assigned to a Project
)
2.Each resource assigned to Project is User
Class
3.Each User
in the Project
also has ReportingHead
and ProjectManager
who are also instance of User
4.Finally there is a Project
class containing project details
Legend of classes used
-
User
-
Project
-
ProjectResource
Table Diagram
-
ProjectResource
-
ResourceId
-
ProjectId
-
UserId
-
ReportingHead
-
ProjectManager
Class Diagram
-
ProjectResource
note:
All the user information is stored in the User table
All the Project information is stored in the project table
Here's the Problem
When the application requests for Resource In a Project operations below are followed
-
First Get the Records for the Project
-
Get the UserId , make the request(using Users DAL
) to get the user instance
-
Get the ProjectId, make the request(using Projects DAL
) to get the project information
-
Finally assign Users
and Project
to instance of ProjectResource
clearly you can see 3 Db Calls
are made here for populating single ProjectResource
but the concerns and who manages the objects are clearly defined. This is the way i have planned to , since there is also connection pooling
available in Sql Server
& ADO.net
There is also another way where all the details are retrieved in single hit using Table Inner Joins and then Populating.
Which way should i really be taking and Why?
Extras:
.NET 2.0,ASP.net 2.0,C#,Sql Server 2005,DB on same machine hosting application.
发布评论
评论(1)
为了获得最佳性能和可扩展性,您应该最大限度地减少与数据库的往返次数。为了向自己证明这一点,只需运行一些基准测试即可;很快就会变得清楚。
实现单次往返的一种方法是使用联接。另一种是返回多个结果集。后者有助于消除可能的重复数据。
For best performance and scalability, you should minimize the number of round-trips to the DB. To prove that to yourself, just run some benchmarks; it becomes clear very quickly.
One approach to a single round-trip is to use joins. Another is to return multiple result sets. The latter can be helpful in eliminating possible duplicate data.