APPLICATION OF PERSISTENT RELATIONAL .NET OBJECTS (USING NHIBERNATE), .NET BASED GRID FRAMEWORK (USING ALCHEMI.NET ) AND RICH WEB CLIENT (USING WPF, SILVERLIGHT ) FOR CONTENT RICH HIGH PERFORMANCE BUSINESS APPLICATIONS. SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE A BSTRACT. NHibernate being a .NET port of the java based object relational framework Hibernate, handles persisting plain .NET objects to and from an underlying relation database. Alchemi allows to aggregate the computing power of networked computers into a virtual supercomputer (a Grid) and to develop applications to run on the grid. Silverlight is designed to provide a richer internet experience for enterprise and consumer applications. In this article we have tried to build a hypothetical design of content rich high performance business applications using these three technologies. Our goal is to simplify the data access layer and allow the developer to use plain old CLR objects for relational data handling. For the performance critical processes of the application we the Alchemi.NET grid is proposed, whose power can be leveraged by identifying the parallel executable sub-processes, in case of a multi user environment each user request can be treated as potential parallel processes by the system. To enrich the user interface with better content, graphics, animation, screen dynamics and user interaction we propose to use Silverlight.
C ONTENTS 1. NHibernate 1.1. Object Relational Mapping 1.2. The Problem 1.3. The Approach 1.4. What is NHibernate? 1.5. NHibernate key features 1.6. Databases supported by NHibernate 1.7. Limitations 1.8. Alternative Technologies 1.9. Prerequisites/System Requirement 1.10. NHibernate Architecture 1.11. Developers’ View 2. Alchemi 2.1. Grid Computing 2.2. What is Alchemi? 2.3. How Alchemi Works 2.4. Prerequisites/System Requirement Date: October 31, 2007. 1
3 3 3 4 4 4 5 5 5 5 5 7 11 11 13 13 14
2
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
2.5. Architecture 2.6. Configuration 2.7. Alternative Technologies 2.8. Developers’ View 3. Silverlight 3.1. What is Silverlight 3.2. Features 3.3. Architecture of Silverlight 3.4. Prerequisites/System Requirement 3.5. Developing a Simple Application 3.6. Deploying Silverlight Application on IIS 3.7. What Next 3.8. Alternative Technologies 4. Usage of NHibernate and Alchemi to build high performance applications 4.1. Persistent Layer - NHibernate 4.2. Business Components 4.3. Grid Layer - Alchemi 4.4. Services 4.5. Presentation/UI Layer 5. Conclusion 6. Web References References Index
14 14 17 18 22 22 22 22 23 23 23 23 24 24 25 25 25 26 27 27 27 27 28
TH TECHNOLOGY SUMMIT
3
1. NH IBERNATE 1.1. Object Relational Mapping. Object-relational mapping is the process of transforming between object and relational modeling approaches and between the systems that support those approaches. Doing a good job at object-relational mapping requires a solid understanding of object modeling and relational modeling, how they are similar, and how they are different. Ideally we should have a single integrated model that described both approaches. This would make sure we understand and explicitly document both concepts and their relationships. This document will present what we believe to be the only correct integration of the two worlds that is suitable for implementation on a relational database. Difficulties occur when we have to deal with the real systems implementing object and relational models. These systems have implementations that are deficient or inconsistent with the theoretical approaches. Relational databases have been deficient for multiple decades in correctly implementing the core concepts of relational theory. On the other hand, object modeling is not standardized, so each programming environment implements its own variation. Because of these deficiencies object-relational mapping is more complicated than it needs to be. Fortunately, object modeling and relational modeling have such different concerns that they are actually extremely compatible. Relational theory is concerned with knowledge and object techniques are concerned with (primarily) behavior. Mapping between the two models requires deciding how the two worlds can refer to each other. We will first describe the two worlds in more detail and then show how they can be integrated.
1.2. The Problem. Data management tasks in object-oriented (OO) programming are typically implemented by manipulating objects, which are almost always non-scalar values. Consider the example of an address book entry, which represents a single person along with zero or more phone numbers and zero or more addresses. This could be modeled in an object-oriented implementation by a ”person object” with ”slots” to hold the data that comprise the entry: the person’s name, a list (or array) of phone numbers, and a list of addresses. The list of phone numbers would itself contain ”phone number objects” and so on. The address book entry is treated as a single value by the programming language (it can be referenced by a single variable, for instance). Various methods can be associated with the object, such as a method to return the preferred phone number, the home address, and so on. Many popular database products, however, such as SQL DBMS products, can only store and manipulate scalar values such as integers and strings, organized within tables. The programmer must either convert the object values into groups of simpler values for storage in the database (convert them back upon retrieval), or only use simple scalar values within the program. Object-relational mapping is used to implement the first approach. The crux of the problem is translating those objects to forms which can be stored in the database, and which can later be retrieved easily, while preserving the properties of the objects and their relationships; these objects are then said to be persistent.
4
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
1.3. The Approach. Object-Relational mapping (aka O/RM, ORM, and O/R mapping) is a programming technique for converting data between incompatible type systems in databases and object-oriented programming languages. This creates, in effect, a virtual object database which can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to create their own ORM tools. An object-relational mapping implementation would need to systematically and predictably choose which tables to use and generate the necessary SQL. In overview, the impedance mismatch between the architectural approach of the object oriented application such as built in Java and where the data is stored in a relational database management system (RDBMS) such as Oracle or IBM’s DB2 creates a rather complex set of challenges to deal with in order to accomplish tasks such as performance, linear scalability, manage the CRUD operations for even the most complex relationships without slowing down, eliminate coding SQL - ODBC - JDBC - Java to save time and create consistency in how this is handled, make maintenance and future application changes simple, requiring little or no effort, etc. The real values in using an ORM tool is to save time, simplify development (i.e. the ORM tool handles the complexity for the developer), increase performance or scalability, and minimize architectural challenges related to inability of the ORM tool or developer’s experience. 1.4. What is NHibernate? NHibernate is an Object-relational mapping (ORM) solution for the Microsoft .NET platform: it provides an easy to use framework for mapping an object-oriented domain model to a traditional relational database. Its purpose is to relieve the developer from a significant amount of relational data persistence-related programming tasks. NHibernate is a port of Hibernate Core for Java to the .NET Framework. It handles persisting plain .NET objects to and from an underlying relational database. Given an XML description of your entities and relationships, NHibernate automatically generates SQL for loading and storing the objects. Optionally, you can describe your mapping metadata with attributes in your source code. NHibernate supports transparent persistence, your object classes don’t have to follow a restrictive programming model. Persistent classes do not need to implement any interface or inherit from a special base class. This makes it possible to design the business logic using plain .NET (CLR) objects and object-oriented idiom. 1.5. NHibernate key features. 3 Natural programming model - NHibernate supports natural OO idiom; inheritance, polymorphism, composition and the .NET collections framework, including generic collections. 3 Native .NET - NHibernate API uses .NET conventions and idioms 3 Support for fine-grained object models - a rich variety of mappings for collections and dependent objects. 3 No build-time bytecode enhancement - there’s no extra code generation or bytecode processing steps in your build procedure
TH TECHNOLOGY SUMMIT
5
3 The query options - NHibernate addresses both sides of the problem; not only how to get objects into the database, but also how to get them out again 3 Custom SQL - specify the exact SQL that NHibernate should use to persist your objects. Stored procedures are supported on Microsoft SQL Server. 3 Support for conversations - NHibernate supports long-lived persistence contexts, detach/reattach of objects, and takes care of optimistic locking automatically 3 Free/open source - NHibernate is licensed under the LGPL (Lesser GNU Public License) 1.6. Databases supported by NHibernate. D D D D D D D D
Microsoft SQL Server 2000, 2005 Oracle Microsoft Access Firebird PostgreSQL DB2 UDB MySQL SQLite
1.7. Limitations. Following are the main limitations of NHibernate 7 The NHibernate persistent classes are not SOAP serializable, thus can’t be exposed via web services. DTO (Data Transfer Objects) components must be used to wrap these beans before exposing via web service. 1.8. Alternative Technologies. As an alternative of NHibernate, LINQ (see http://msdn2.microsoft.com/hi-in/netframework/aa904594.aspx) can be used. The LINQ Project is a codename for a set of extensions to the .NET Framework that encompass language-integrated query, set, and transform operations. It extends C# and Visual Basic with native language syntax for queries and provides class libraries to take advantage of these capabilities. 1.9. Prerequisites/System Requirement. To use NHibernate Microsoft .NET Framework 1.1 or above must be installed on the system. 1.10. NHibernate Architecture. Figuare 1 is the high level architecture of NHibernate. Here are some definitions of the objects in the diagrams: D ISessionFactory (NHibernate.ISessionFactory) A threadsafe (immutable) cache of compiled mappings for a single database. A factory for ISession and a client of IConnectionProvider. Might hold an optional (second-level) cache of data that is reusable between transactions, at a process- or cluster-level. D ISession (NHibernate.ISession) A single-threaded, short-lived object representing a conversation between the application and the persistent store. Wraps an ADO.NET connection.
6
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
F IGURE 1. NHibernate Architecture
D
D
D
D
Factory for ITransaction. Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier. Persistent Objects and Collections Short-lived, single threaded objects containing persistent state and business function. These might be ordinary POCOs, the only special thing about them is that they are currently associated with (exactly one) ISession. As soon as the Session is closed, they will be detached and free to use in any application layer (e.g. directly as data transfer objects to and from presentation). Transient Objects and Collections Instances of persistent classes that are not currently associated with a ISession. They may have been instantiated by the application and not (yet) persisted or they may have been instantiated by a closed ISession. ITransaction (NHibernate.ITransaction) (Optional) A single-threaded, short-lived object used by the application to specify atomic units of work. Abstracts application from underlying ADO.NET transaction. An ISession might span several ITransactions in some cases. IConnectionProvider (NHibernate.Connection.IConnectionProvider) (Optional) A factory for ADO.NET connections and commands. Abstracts application from the concrete vendor-specific implementations of IDbConnection and IDbCommand. Not exposed to application, but can be extended/implemented by the developer.
TH TECHNOLOGY SUMMIT
7
D IDriver (NHibernate.Driver.IDriver) (Optional) An interface encapsulating differences between ADO.NET providers, such as parameter naming conventions and supported ADO.NET features. D ITransactionFactory (NHibernate.Transaction.ITransactionFactory) (Optional) A factory for ITransaction instances. Not exposed to the application, but can be extended/implemented by the developer. 1.11. Developers’ View. Environment Configuration. NHibernate environment configuration like database connection string can be done in three ways (1) Specifying environment settings in the configuration file (Web.Config or App.Config) (2) Via the hibernate.cfg.xml of the main project. (3) Configured programmatically. Here (listing 1) we give the content of a sample hibernate.cfg.xml file L ISTING 1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
xml version = " 1.0 " encoding = " utf -8 " ? > < hibernate - configuration xmlns = " urn:nhibernate - configuration -2.2 " > < session - factory > < property name = " connection . provider " > NHibernate . Connection . D r iv e r C on n e c t io n P r o vi d e r property > < property name = " connection . driver_class " > NHibernate . Driver . SqlClientDriver property > < property name = " connection . connection_string " > user = sa ; password = password1 $; Initial Catalog = WEBAPPDBPOC ; Data Source = CTSINCALSDAI \ VRGUAT1 ; Connection Timeout =0; property > < property name = " show_sql " > true property > < property name = " dialect " > NHibernate . Dialect . MsSql2000Dialect property > < property name = " use_outer_join " > true property > < property name = " query . substitutions " > true 1 , false 0 , yes ’Y ’ , no ’N ’ property > < mapping assembly = " POC . ClassLibrary " / > session - factory > hibernate - configuration >
The Persistent POCO class. Here (listing 2) is an example POCO class for the Item entity in the database -
8
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
L ISTING 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
[ System . S e r i a l i z a b l e A t t ribu te ()] [ System . Xml . Serialization . XmlIncludeAttribute ( typeof ( POC . ClassLibrary . ItemAttribute ))] [ System . Xml . Serialization . SoapIncludeAttri bute ( typeof ( POC . ClassLibrary . ItemAttribute ))] public class Item { private int itemId ; private string itemCode ; private string itemName ; ... private POC . ClassLibrary . ItemCategoryMaster it em Ca te go ry Ma ster ; private System . Collections . IList itemAttributes ; public virtual int ItemId { get { return this . itemId ; } set { this . itemId = value ; } } public virtual string ItemName { get { return this . itemName ; } set { this . itemName = value ; } } ... public virtual POC . ClassLibrary . ItemCategoryMaster It em Ca te go ry Ma ster { get { return this . itemCategoryMaster ; } set { this . it emCategoryMaster = value ; } } [ System . Xml . Serialization . XmlIgnoreAttribute ()] [ System . Xml . Serialization . SoapIgnoreAttribute ()] public virtual System . Collections . IList ItemAttributes { get { if ((( this . itemAttributes != null ) && ( typeof ( System . Array ). IsAssignableFrom ( this . itemAttributes . GetType ()) == true ))) { this . ItemAttributes = new System . Collections . ArrayList ( this . itemAttributes ); } return this . itemAttributes ; } set { this . itemAttributes = value ; } }
TH TECHNOLOGY SUMMIT
53
9
}
The O/R Mapping. Here (listing 3) is an example O/R mapping done for the Item entity via the Item.hbm.xml L ISTING 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
< hibernate - mapping default - cascade = " none " xmlns = " urn:nhibernate - mapping -2.2 " > < class name = " POC . ClassLibrary . Item , POC . ClassLibrary " table = " Item " > < id name = " ItemId " type = " System . Int32 " column = " Item_Id " unsaved - value = " 0 " > < generator class = " native " / > id > < property name = " ItemName " type = " System . String " column = " Item_Name " not - null = " true " length = " 255 " / > ... < many - to - one name = " It em Ca te goryMaster " class = " POC . ClassLibrary . ItemCategoryMaster , POC . ClassLibrary " fetch = " select " > < column name = " Item_Category_Id " not - null = " false " / > many - to - one > < bag name = " ItemAttributes " inverse = " true " lazy = " false " cascade = " none " > < key > < column name = " Item_Id " not - null = " true " / > key > bag > class > hibernate - mapping >
Accessing data using the persistent objects. Here (listing 4) is an example of accessing all items using the Item POCO L ISTING 4 1 2 3 4 5
public List < Item > AllItems { get { List < Item > items = null ;
10
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
try { ICriteria criteria = mSession . CreateCriteria ( typeof ( Item ) ); criteria . AddOrder ( NHEx . Order . Asc ( " ItemName " ) ); items = new List < Item > ( criteria . List < Item > ( ) ); if ( items == null || items . Count < 1 ) { return null ; } else { return items ; } } catch ( Exception ex ) { throw ex ; } } }
One more example (listing 5) for a particular item id L ISTING 5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
public Item GetItemByItemId ( int itemId ) { List < Item > items = null ; try { ICriteria criteria = mSession . CreateCriteria ( typeof ( Item ) ); criteria . Add ( NHEx . Expression . Eq ( " ItemId " , itemId ) ); criteria . AddOrder ( NHEx . Order . Asc ( " ItemName " ) ); items = new List < Item > ( criteria . List < Item > ( ) ); if ( items == null || items . Count < 1 ) { return null ; } else
TH TECHNOLOGY SUMMIT
23 24 25 26 27 28 29 30 31
11
{ return items [ 0 ]; } } catch ( Exception ex ) { throw ex ; } }
2. A LCHEMI 2.1. Grid Computing. Grid computing is a critical shift in thinking about how to maximize the value of computing resources. Because it is an emerging technology, grid computing can mean different things to different people. But here is a simple, serviceable definition for the concept of grid computing: Grid computing allows you to unite pools of servers, storage systems, and networks into a single large system so you can deliver the power of multiple-systems resources to a single user point for a specific purpose. To a user, data file, or an application, the system appears to be a single enormous virtual computing system. Grid computing is the next logical step in distributed networking. Just as the Internet allows users to share ideas and files as the seeds of projects, grid computing lets us share the resources of disparate computer systems so people can actually start working on those projects. Grid computing takes the ability for computers (and their users) to communicate a step further: With grid computing, you can reach out and use computational or storage resources on machines other than your own. With grid computing, an organization can transform its distributed and difficultto-manage systems into a large virtual computer that can be set loose on problems and processes too complex for a single computer to handle efficiently. The problems to be solved can involve data processing, network bandwidth, or data storage. The systems linked in a grid might be in the same room or distributed around the world. They might be running different operating systems on many hardware platforms. They might even be owned by different organizations. Regardless of the depth of a grid’s resources, all the grid user experiences is the processing resources of a very large virtual computer. The major purpose of a grid is to virtualize resources to solve problems. The main resources grid computing is designed to give access to include, but are not limited to: D Computing/processing power D Data storage/networked file systems D Communications and bandwidth D Application software Since the concept of putting grids into real-world practice is still relatively new, another good way to describe a grid is to describe what it isn’t. The following are not grids: D Clusters D Network-attached storage devices
12
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
D Scientific instruments D Networks Each might be an important component of a grid, but by itself, doesn’t constitute a grid. Being able to tie together several million computers – clusters, workstations, desktop PCs, supercomputers – with data storage, instruments, visualization devices is the dream grid computing strives to achieve and the reality of grid computing could be revolutionary to science and industry. So, what does it take to make the vision of the grid computing concept a reality? It requires standard and seamless, open general-purpose protocols and interfaces, all of which are being defined now and are similar to those that enable access to information from the Web. Key Components of Grid Computing. There are six major components to grid computing: (1) (2) (3) (4) (5) (6)
Security User interface Workload management Scheduler Data management Resource management
Computers on a grid are networked and running applications. They can also be handling sensitive or extremely valuable data, so the security component of grid computing is of paramount concern. This component includes elements such as encryption, authentication, and authorization. Accessing information on the grid is also quite important, and the user interface component handles this task for the user. It often comes in one of two ways: D An interface provided by an application that the user is running D An interface provided by the grid administrator, much like a Web portal that provides access to the applications and resources available on the grid in a single virtual space The portal-style interface is also important because it can be the help space for users to learn how to query the grid. Applications a user wants to run on a grid must be aware of the resources available. This is where a workload management service comes in handy. An application can communicate with the workload manager to discover the available resources and their status. A scheduler is needed to locate the computers on which to run an application and to assign the jobs required. This can be as simple as taking the next available resource, but this task often involves prioritizing job queues, managing the load, finding workarounds when encountering reserved resources, and monitoring progress. If an application is running on a system that doesn’t hold the data the application needs, a secure, reliable data management facility takes care of moving that data to the right place across various machines, encountering various protocols. To handle such core tasks as launching jobs with specific resources, monitoring the status of those jobs, and retrieving results, a resource management facility is necessary.
TH TECHNOLOGY SUMMIT
13
It’s important to remember that grid computing doesn’t operate in a vacuum. Just the opposite: It potentially involves every protocol and computer technology in operation today. With that in mind, we’ve provided links to other technologies and standards you might need to understand to fully appreciate the scope of grid computing’s power. 2.2. What is Alchemi? The idea of metacomputing is very promising as it enables the use of a network of many independent computers as if they were one large parallel machine, or virtual supercomputer for solving large-scale problems in science, engineering, and commerce. With the exponential growth of global computer ownership, local networks and Internet connectivity, this concept has been taken to a new level - grid computing. There is rapidly emerging interest in grid computing from commercial enterprises. A Microsoft Windows based grid computing infrastructure will play a critical role in the industry-wide adoption of grids due to the large-scale deployment of Windows within enterprises. This enables the harnessing of the unused computational power of desktop PCs and workstations to create a virtual supercomputing resource at a fraction of the cost of traditional supercomputers. However, there is a distinct lack of service oriented architecture-based grid computing software in this space. To overcome this limitation, Alchemi is implemented on the Microsoft .NET. While the notion of grid computing is simple enough, the practical realization of grids poses a number of challenges. Key issues that need to be dealt with are security, heterogeneity, reliability, application composition, scheduling, and resource management. The Microsoft .NET Framework provides a powerful toolset that can be leveraged for all of these, in particular support for remote execution (via .NET Remoting and web services), multithreading, security, asynchronous programming, disconnected data access, managed execution and crosslanguage development, making it an ideal platform for grid computing middleware. The Alchemi grid computing framework was conceived with the aim of making grid construction and development of grid software as easy as possible without sacrificing flexibility, scalability, reliability and extensibility. The key features supported by Alchemi are: D Internet-based clustering of desktop computers without a shared file system; D federation of clusters to create hierarchical, cooperative grids; D dedicated or non-dedicated (voluntary) execution by clusters and individual nodes; D object-oriented grid thread programming model (fine-grained abstraction); and D Web services interface supporting a grid job model (coarse-grained abstraction) for cross-platform interoperability e.g. for creating a global and cross-platform grid environment via a custom resource broker component. 2.3. How Alchemi Works. There are four types of distributed components (nodes) involved in the construction of Alchemi grids and execution of grid applications: Manager, Executor, User and Cross-Platform Manager.
14
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
F IGURE 2. How Alchemi Works A grid is created by installing Executors on each machine that is to be part of the grid and linking them to a central Manager component. The Windows installer setup that comes with the Alchemi distribution and minimal configuration makes it very easy to set up a grid. An Executor can be configured to be dedicated (meaning the Manager initiates thread execution directly) or non-dedicated (meaning that thread execution is initiated by the Executor.) Non-dedicated Executors can work through firewalls and NAT servers since there is only one-way communication between the Executor and Manager. Dedicated Executors are more suited to an intranet environment and non-dedicated Executors are more suited to the Internet environment. Users can develop, execute and monitor grid applications using the .NET API and tools which are part of the Alchemi SDK. Alchemi offers a powerful grid thread programming model which makes it very easy to develop grid applications and a grid job model for grid-enabling legacy or non-.NET applications. An optional component (not shown) is the Cross Platform Manager web service which offers interoperability with custom non-.NET grid middleware. 2.4. Prerequisites/System Requirement. To use Alchemi.NET Microsoft .NET Framework 1.1 or above must be installed on the system(s). The Manager should be installed on a stable and reasonably capable machine. The Manager requires SQL Server 2000 (or above) or MSDE 2000. The Alchemi Executor can be installed in two modes - as a normal Windows desktop application As a windows service (supported only on Windows NT/2000/XP/2003). 2.5. Architecture. Alchemi follows the master-worker parallel programming paradigm in which a central component dispatches independent units of parallel execution to workers and manages them. This smallest unit of parallel execution is a grid thread, which is conceptually and programmatically similar to a thread object (in the object-oriented sense) that wraps a normal multitasking operating system thread. A grid application is defined simply as an application that is to be executed on a grid and that consists of a number of grid threads. Grid applications and grid threads are exposed to the grid application developer via the object oriented Alchemi .NET API. 2.6. Configuration.
TH TECHNOLOGY SUMMIT
15
F IGURE 3. Alchemi Architecture D Cluster (Desktop Grid) The basic deployment scenario - a cluster - consists of a single Manager and multiple Executors that are configured to connect to the Manager. One or more Owners can execute their applications on the cluster by connecting to the Manager. Such an environment is appropriate for deployment on Local Area Networks as well as the Internet. The operation of the Manager, Executor and Owner components in a cluster is as described above.
F IGURE 4. Cluster
16
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
F IGURE 5. Legends D Multi-Cluster A multi-cluster environment is created by connecting Managers in a hierarchical fashion. As in a single-cluster environment, any number of Executors and Owners can connect to a Manager at any level in the hierarchy. An Executor and Owner in a multi-cluster environment connect to a Manager in the same fashion as in a cluster and correspondingly their operation is no different from that in a cluster. The key to accomplishing multi-clustering in Alchemi’s architecture is the fact that a Manager behaves like an Executor towards another Manager since the Manager implements the interface of the Executor. A Manager at each level except for the topmost level in the hierarchy is configured to connect to a higher level Manager as an intermediate Manager and is treated by the higher level-Manager as an Executor. Such an environment is more appropriate for deployment on the Internet. The operation of an intermediate Manager in a multi-cluster environment therefore, must be discussed with respect to the behavior of an Executor and is as follows. Once Owners have submitted grid applications to their respective Managers, each Manager has local grid threads waiting to be executed. As discussed, threads are assigned the highest priority by default (unless the priority is explicitly specified during creation) and threads are scheduled and executed as normal by the Manager’s local Executors. Note that an ’Executor’ in this context could actually be an intermediate Manager, since it is treated as an Executor by the higher-level Manager. In this case after receiving a thread from the higher-level Manager, it is scheduled locally by the intermediate Manager with a priority reduced by one unit and is executed as normal by the Manager’s local Executors (again, any of which could be intermediate Managers). In addition, at some point the situation may arise when a Manager wishes to allocate a thread to one of its local Executors (one or more of
TH TECHNOLOGY SUMMIT
17
which could an intermediate Manager), but there are no local threads waiting to be executed. In this case, if the Manager is an intermediate Manager, it requests a thread from its higher-level Manager, reduced the priority by one unit and schedules it locally. In both of these cases, the effect of the reduction in priority of a thread as it moves down the hierarchy of Managers is that the closer a thread is submitted to an Executor, the higher is the priority that it executes with. This allows a portion of an Alchemi grid that is within one administrative domain (i.e. a cluster or multi-cluster under a specific administrative domain Manager) to be shared with other organizations to create a collaborative grid environment without impacting on its utility to local users. As with an Executor, an intermediate Manager must be configured for either dedicated or non-dedicated execution. Not only does its operation in this respect mirror that of an Executor, the same benefits of flexible resource management and deployment under network constraints apply.
F IGURE 6. Multi Cluster D Cross-Platform Grid The Cross-Platform Manager can be used to construct a grid conforming to the classical global grid model. A grid middleware component such as a broker can use the Cross-Platform Manager web service to execute cross-platform applications (jobs within tasks) on an Alchemi node (cluster or multi-cluster) as well as resources grid-enabled using other technologies such as Globus. 2.7. Alternative Technologies. As an alternative Bayanihan Computing.NET (see http://bayanihancomputing.net/) can be used. Bayanihan Computing .NET is a generic Grid computing framework based on Microsoft .NET that uses Web services to harness computing resources through ’volunteer’ computing similar to projects such as SETI@Home, and to make the computing resources easily accessible through easy-to-use and interoperable computational Web services.
18
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
F IGURE 7. Cross-Platform Grid Globus (see http://www.globus.org/) is also an alternative grid solution based on Java. The Globus Toolkit is an open source software toolkit used for building Grid systems and applications. It is being developed by the Globus Alliance and many others all over the world. A growing number of projects and companies are using the Globus Toolkit to unlock the potential of grids for their cause. 2.8. Developers’ View. Implementing the GThread class. To write a grid thread class (listing 6), we derive a new class from the Alchemi.Core.Owner,GThread class and override the void Start() method. We must also add the Serializable attribute to it: L ISTING 6 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
using using using using using using
System ; System . Threading ; System . Reflection ; System . Text ; Alchemi . Core ; Alchemi . Core . Owner ;
namespace POC . Alchemi . PiCalculator { [ Serializable ] public class PiCalcGridThread : GThread { private int startDigitNum ; private int numDigits ; private string result ; public int StartDigitNum { get { return startDigitNum ; } } public int NumDigits { get { return numDigits ; } } public string Result {
TH TECHNOLOGY SUMMIT
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
19
get { return result ; } } public PiCalcGridThread ( int startDigitNum , int numDigits ) { this . startDigitNum = startDigitNum ; this . numDigits = numDigits ; } public override void Start () { StringBuilder temp = new StringBuilder (); PlouffeBellard pb = new PlouffeBellard (); for ( int i = 0; i <= Math . Ceiling ( ( double ) numDigits / 9); i ++) { temp . Append ( pb . CalculatePiDigits ( startDigitNum + ( i * 9 ) ) ); } result = temp . ToString ( ). Substring ( 0 , numDigits ); } } }
The Grid Application. Now that we have written our parallel code, we can go about writing code (listing 7) that runs it on the grid. For this, we use the GApplication class. GApplication is a container for executing grid threads and is used to interact with the grid. In the Main method of the application, 100 PrimeNumberChecker grid threads are created and added to the App grid application’s Threads property (a GThread collection). L ISTING 7 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
using using using using using using
System ; System . Reflection ; System . Text ; Alchemi . Core ; Alchemi . Core . Owner ; Alchemi . Core . Utility ;
namespace POC . Alchemi . PiCalculator . Main { class PiCalculatorMain { static int numThreads = 10; static int digitsPerThread = 10; static int numberOfDigits = numThreads * digitsPerThread ; static GApplication app ;
20
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
static int th = 0; [ STAThread ] static void Main ( ) { try { // get the number of digits from the user bool n um ber OfDi gits Ente red = false ; while ( ! num berO fDig itsE nter ed ) { try { Console . Write ( " Digits to calculate : " ); numberOfDigits = Int32 . Parse ( Console . ReadLine ( ) ); if ( numberOfDigits > 0 ) { num berO fDig itsE nter ed = true ; } } catch ( Exception ) { Console . WriteLine ( " Invalid numeric value . " ); nu mber OfDi gits Ente red = false ; } } // get settings from user GConnection gc = new GConnection ( " localhost " , " 9000 " , " user " , " user " ); // create a new grid application app = new GApplication ( gc ); app . ApplicationName = " PI Calculator - Alchemi POC " ; // add the module containing PiCalcGridThread // to the application manifest app . Manifest . Add ( new ModuleDependency ( typeof ( POC . Alchemi . PiCalculator . PiCalcGridThread ). Module ) ); NumThreads = ( Int32 ) Math . Floor ( ( double ) numberOfDigits / digitsPerThread ); if ( digitsPerThread * numThreads < numberOfDigits ) {
TH TECHNOLOGY SUMMIT
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
21
NumThreads ++; } // create and add the required number of grid threads for ( int i = 0 ; i < numThreads ; i ++ ) { int startDigitNum = 1 + ( i * digitsPerThread ); // / // / // / // / int
the number of digits for each thread Each thread will get DigitsPerThread digits except the last one which might get less digitsForThisThread = Math . Min ( digitsPerThread , numberOfDigits - i * digitsPerThread );
PiCalcGridThread thread = new POC . Alchemi . PiCalculator . PiCalcGridThread ( startDigitNum , digitsForThisThread ); app . Threads . Add ( thread ); } // subcribe to events app . ThreadFinish += new GThreadFinish ( ThreadFinished ); app . ApplicationFinish += new GApplicationFinish ( A p plicationFinished ); // start the grid application app . Start ( ); } catch ( Exception e ) { Console . WriteLine ( " ERROR : {0} " , e . StackTrace ); } Console . ReadLine ( ); } static void ThreadFinished ( GThread thread ) { th ++; // Console . WriteLine (" grid thread # {0} finished executing " , // thread . Id ); } static void A p plicationFinished ( ) { StringBuilder result = new StringBuilder ( ); for ( int i = 0 ; i < app . Threads . Count ; i ++ )
22
124 125 126 127 128 129 130 131 132 133 134 135 136 137
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
{ POC . Alchemi . PiCalculator . PiCalcGridThread pcgt = ( POC . Alchemi . PiCalculator . PiCalcGridThread ) app . Threads [ i ]; result . Append ( pcgt . Result ); } Console . WriteLine ( " The value of Pi to {0} digits is :{1} " , numberOfDigits , result ); } } }
3. S ILVERLIGHT 3.1. What is Silverlight. Silverlight (formerly known as WPF/E or Windows Presentation Foundation / Everywhere) is a cross-platform browser plug-in being developed by Microsoft that is designed to provide a richer internet experience for enterprise and consumer applications. Silverlight 1.0 has been called a ”Flash killer” in that it will provide enhanced animation, vector graphics, and video playback capabilities. Although these features are interesting for improving the multimedia experience on the web, the real potential for Silverlight lies in the feature set to be released with version 1.1 3.2. Features. The Silverlight version 1.0 feature set includes the following: 3 Declarative content format based on Extensible Application Markup Language (XAML). 3 JavaScript-based programming model. 3 Deployment options for content: in-line with the HTML page, as loose files, or in a compressed zip package. 3 Media support, including support for Windows Media Video (WMV), Windows Media Audio (WMA), and MPEG Audio Layer-3 (MP3), delivered with Windows Media Services or progressive download. Also includes support for client-side playlists (ASX files). 3 Text. 3 Image (PNG and JPG) support. 3 Anti-aliased vector graphics engine. 3 Animation. 3 Mouse and keyboard input. 3 HTTP downloader. 3 Full-screen rendering support. 3.3. Architecture of Silverlight. The Silverlight runtime enables users to integrate media, vector graphics, text, and images into an interactive application. This section (see figure 8) discusses some of the key components provided in Silverlight 1.0.
TH TECHNOLOGY SUMMIT
23
F IGURE 8. Silverlight Architecture 3.4. Prerequisites/System Requirement. Following are the components we need to develop a Silverlight application D .Net Framework -3.0 and above. D IDE Version - Visual Studio 2005 Team Edition with the WPF extension Or VS 2008 D Silver Light 1.0 Runtime D Visual Studio 2005 service pack 1 for Silver Light 1.0 project template D Microsoft Expression Blend( Optional for design purpose ) 3.5. Developing a Simple Application. Silver Light Application=XAML+JAVA Script +Html Structure of a Silver Light Application. See figure 9 Function of SilverLight.js. See figure 10 3.6. Deploying Silverlight Application on IIS. To deploy the application in a web server we need to change the mime type of the server (see figure 11). .Net framework (V3.0) or silver light component is not required on the server. Just we have to enter following entries in the mime type section Extension: .XAML Mime Type: application/xaml+xml 3.7. What Next. Silver light 1.0 is still in the nascent state. Main power of the silver light will be revealed on the version 1.1. Silver light 1.1 will consists following features D C# coding architecture. D Much more flexibility on the graphics. D Much more basic controls such as text box radio button etc. D Communication with web service.
24
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
F IGURE 9. Structure Of Silverlight Application
F IGURE 10. Function Of SilverLight.js 3.8. Alternative Technologies. Flex (see http://flex.org/ and http://www.adobe.com/devnet/flex/) is a good alternative to Silverlight. Flex is a framework that helps you build dynamic, interactive rich Internet applications. Flex applications are delivered on the web via the Flash Player or to the desktop via Adobe Apollo. 4. U SAGE OF NH IBERNATE AND A LCHEMI TO BUILD HIGH PERFORMANCE APPLICATIONS
See figure 12
TH TECHNOLOGY SUMMIT
25
F IGURE 11. Deploying Silverlight Application on IIS
4.1. Persistent Layer - NHibernate. We propose to implement NHibernate at this layer, to leverage power of object relational persistence along with the ease and simplification of the coding/construction effort. This layer consists of the bean (oops sorry Java guys for borrowing your term) classes which encapsulate the DB entities as a wrapper to be used directly in the application layer. NHibernate OR mapping xml does the underlying DB Entity - Persistent Object mapping. 4.2. Business Components. The Business component layer consists of the business entities which either inherit the persistent objects or use those persistent object (via messaging or containment) to implement the business objectives of the application. 4.3. Grid Layer - Alchemi. This layer uses the Alchemi grid distributed either as a uni-cluster or a multi cluster. The Grid Executor comprises of the GThread subclasses. The GThread subclasses are implemented for the performance critical
26
SATYAKI CHATTERJEE AND SOMNATH MUKHERJEE
F IGURE 12. Application Architecture operations of the application; like search. The Grid Application is the main application component of the Alchemi layer which controls and manages the GThread components for which thread to be activated on which context and with the proper parameter set. 4.4. Services. The Services layer consists of the Web Services which internally uses the DTO (Data Transfer Objects) components, and exposes the application
TH TECHNOLOGY SUMMIT
27
services in terms of the DTO entities. Using the DTO classes is necessary because NHibernate base beans are not SOAP serializable, thus can’t be exposed via web services directly. 4.5. Presentation/UI Layer. The UI layer (the web pages); use the web services for the core functionalities. Silverlight can be used in this layer. 5. C ONCLUSION To keep stress on the main two aspects, viz. Content Rich and High Performance, of the proposed solution, we have tried to glue three frameworks each being master in their own domain. It may seem that we compromising performance by using NHibernate as an object relational wrapper over the relational database. But the simplicity of application development and usage of plain CLR objects in the grid application makes it much maintainable. Moreover NHibernate do not restrict usage of stored procedures. Some of the application logic, which can not be parallelized, can be implemented by stored procedures. The plus point of using Alchemi.NET grid for performance critical computations is its scalability. Grid executors can be added at any time of the application lifecycle. Silverlight, which is still in its budding phase, is going to be a leader in the rich internet applications. 6. W EB R EFERENCES (1) http://www.nhibernate.org/ (2) http://www.alchemi.net/ (3) http://www.silverlight.net/ R EFERENCES [LBRV03] Akshay Luther, Rajkumar Buyya, Rajiv Ranjan, and Srikumar Venugopal. Alchemi: A .net-based grid computing framework and its integration into global grids, 2003.
I NDEX .NET Remoting, 13 .NET collections, 4
ITransaction, see also NHibernate.ITransaction
ADO.NET, 7 Alchemi, 13, 14, 17 Alchemi .NET API, 14 Alchemi SDK, 14 Animation, 22 Anti-aliased, 22 ASX, 22 asynchronous programming, 13
JavaScript, 22 JPG, 22 LGPL, 5 LINQ, 5 long-lived persistence contexts, 5 managed execution, 13 Manager, 13–16 metacomputing, 13 metadata, 4 Microsoft .NET, 4, 13 Microsoft .NET Framework, 5, 14 Microsoft Expression Blend, 23 Microsoft SQL Server, 5 MP3, 22 MPEG Audio Layer-3, see also MP3 MSDE 2000, 14 Multi-Cluster, 16 multithreading, 13
Bayanihan Computing.NET, 17 bytecode, 4 C#, 23 CLR, 4 Cluster (Desktop Grid), 15 coarse-grained abstraction, 13 composition, 4 cooperative grids, 13 cross-language development, 13 Cross-Platform Grid, 17 cross-platform interoperability, 13 Cross-Platform Manager, 13
NHibernate, 3, 4 NHibernate.Connection.IConnectionProvider, 6 NHibernate.Driver.IDriver, 7 NHibernate.ISession, 5 NHibernate.ISessionFactory, 5 NHibernate.ITransaction, 6 NHibernate.Transaction.ITransactionFactory, 7 non-dedicated execution, 13, 14
Data Transfer Objects, 5 DBMS, 3 dedicated execution, 13, 14 disconnected data access, 13 distributed networking, 11 Executor, 13–16 Extensible Application Markup Language, see also XAML
O/R mapping, see also Object Relational mapping O/RM, see also Object Relational mapping Object Relational Mapping, 3, 4 object-oriented programming, 3 optimistic locking, 5 ORM, see also Object Relational mapping ORM tools, 4 Owner, 15, 16
fine-grained abstraction, 13 firewalls, 14 Flash Player, 24 Flex, 24 Full-screen, 22 GApplication, 19 generic collections, 4 Globus Toolkit, 18 Grid Computing, 11 GThread, 18, 19
Persistent Objects and Collections, 6 Plain Old CLR Object, see also POCO PNG, 22 POCO, 6 polymorphism, 4 portal-style interface, 12
Hibernate, 4 hierarchical, 13, 16 HTTP downloader, 22 IDbCommand, 6 IDbConnection, 6 IIS, 23 inheritance, 4 Internet-based clustering, 13 ISession, see also NHibernate.ISession
RDBMS, see also relational database management system relational database management system, 4 Relational databases, 3 relational models, 3 28
TH TECHNOLOGY SUMMIT
security, 13 Serializable, 18 Silverlight, 22 SilverLight.js, 23 SOAP serializable, 5 SQL, 3–5 SQL Server 2000, 14 Start(), 18 Transient Objects and Collections, 6 User, 13 vector graphics, 22 virtual object database, 4, 17 Visual Studio 2005 service pack 1, 23 web service, 5, 13 Windows Media Audio, see also WMA Windows Media Video, see also WMV WMA, 22 WMV, 22 WPF, 23 XAML, 22
29