Latest Entries »

?Download MultiMap.cs
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
53
54
55
56
57
58
59
60
61
62
63
64
65
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace com.firatatagun.net
{
public class MultiMap<T,V>
{
 
private IDictionary<T, IList<V>> multiMap = new Dictionary<T, IList<V>>();
 
public void Add(T t, V value)
{
 
IList<V> list;
if (multiMap.TryGetValue(t, out list))
{
list.Add(value);
}
else
{
list = new List<V>();
list.Add(value);
multiMap.Add(t, list);
}
 
}
 
public IEnumerable<T> Keys
{
get
{
return this.multiMap.Keys;
}
}
 
public IEnumerable<IList<V>> Values
{
get
{
return this.multiMap.Values;
}
}
 
public IList<V> this[T index]
{
get
{
IList<V> list;
if (multiMap.TryGetValue(index, out list))
{
return list;
}
else
{
list = new List<V>();
return list;
}
 
}
}
 
}
}

C# – Default access modifiers

Default access modifier for a class is private.

Default access modifier for interfaces are public, because they should be inherited by it s implementers.

C# – IEnumerator and IEnumerable

IEnumerator and IEnumerable are interfaces that are used to enumerate through a collection.
IEnumerator has a non generic correspondence IEnumerator which has MoveNext() method that returns a boolean, Current read only property that returns the current item in the collection. Reset, which resets the pointer (Enumerator) to -1. IEnumerator pointers begin with -1, and upon moving to the next element, pointer becomes 0, which we usually start processing. Classes that implments IEnumerable interface should implement GetEnumerator, IEnumerable.GetEnumerator methods which exposes the Enumerator to the caller.

Moreover, classes that implements IEnumerable and IEnumerator should implements all the methods and properties that belong to IEnumerator and IEnumerable, and also Dispose method.

class MyEnumerator : IEnumerator, IEnumerable
{
private List list;
private int pointer = -1;

public MyEnumerator()
{
list = new List();
}

public T this[int i]
{
set
{
list.Add(value);
}

get
{
return list[i];
}
}

public T Current
{
get
{
return list[pointer];
}
}

object IEnumerator.Current
{
get
{
return list[pointer];
}
}

public bool MoveNext()
{
if (++pointer < list.Count)
{
return true;
}
else
{
return false;
}
}

public void Reset()
{

}

public void Dispose()
{

}

public IEnumerator GetEnumerator()
{
return this;
}

IEnumerator IEnumerable.GetEnumerator()
{
return this;
}

}

C# Operator Overloading

C# allows programmers to overload all of the operators.

Equality ( == ) operator can be overloaded as follows:

public static bool operator ==(T item1, T Item2)
{
return item1.SomeProperty == item2.SomeProperty && item1.AnotherProperty == item2.AnotherProperty;
}

public static bool operator !=(T item1, T item2)
{
return !(item1==item2);
}

public static bool operator <(T item1, T item2)
{
return item1.SomeProperty < item2.SomeProperty;
}

etc.

Operators that can be Overloaded:

+, -, *, /, %, &, |, <<, >> All C# binary operators can be overloaded.

+, -, !, ~, ++, –, true, false All C# unary operators can be overloaded.

==, !=, <, >, <= , >= All relational operators can be overloaded,
but only as pairs.

&&, || They can’t be overloaded

() (Conversion operator) They can’t be overloaded

+=, -=, *=, /=, %= These compound assignment operators can be
overloaded. But in C#, these operators are
automatically overloaded when the respective
binary operator is overloaded.

=, . , ?:, ->, new, is, as, size of These operators can’t be overloaded

Following method replaces a character at a given index of a string.

// Replaces a character in a string with the character specified.
void replaceCharWithChar(ref string text, int index, char charToUse)
{
char[] tmpBuffer = text.ToCharArray();

tmpBuffer [index] = charToUse;

text = new string(tmpBuffer);
}

Scalable Data Center Networks

Firat Atagun

Abstract

Data centers offer many benefits for hosting and colocating applications, data storage, servers and services. As the demand to data center’s services and resources increases; number of servers and hardware in the data centers increases exponentially. Interconnecting exponentially increasing number of services, hardware and servers while offering scalability, reliability, efficiency, fault tolerance, easily maintainability, and high network capacity becomes a challenge for data center networks. Other difficulties while designing and deploying a data center network are physical expansion, routing and forwarding inside the data center which should be scalable, reliable, and fault tolerant. In this paper I will research the characteristics, similarities and differences of approaching scalable data center network that are studied in the following three papers, [1] DCell: A scalable and fault tolerant network structure for data centers; recursively defined network architecture is explained to interconnect servers while scalability, fault tolerance and network resource usage is utilized. In [2] Portland: A scalable fault tolerant layer 2 data center network fabric; offers scalable, fault tolerant data center network design with conventional but improved data center network by using “Fat Tree” based structure. In [3] VL2: A scalable and flexible data center network; scalability, reliability and fault tolerance of a new approach to data center network is explained by network transparency, abstraction, load balancing and incremental expansion methods.

General Terms:
Design, Algorithms, Scalability, Fault Tolerance

Keywords:
Data center network, Scalability, Fault tolerance

Presentation : Scalable Data Center Networks

Paper: Scalable Data Center Networks

Multi Layer, Multi Player Distributed (Cluster or Grid) Game Architecture

Multi player games have been very popular since last couple years. Game companies are doing a good job
on scaling multiplayer games. There are two architectures that supports interactive systems : P2P and Client Server
which in this case is Client Multi Server. Both of the architectures can be used for developing such games.

Using P2P, the players can have a copy of the Virtual World and players which are online at a certain time, and players can
receive other players action and movements from the other players machines, this case is player machines uses IP-Multicast
, drawbacks for this schema is usage of bandwidth, if the players dont have powerful machines they wont be able to join the world,
and IP-Multicast is not well supported.

Using Client Multi server is yet another architecture that can be used for Multi player games, In this model we have
synchronization problem, each player in the same world would need to have the same set of data, and there can be collision,
it would be hard to detect all these, and it would increase the latency etc. In order to avoid this, load balancers can be placed
in front of the game servers, but then the game servers should be synchronized. Moreover these servers should be either very
powerful or there should be several servers that are doing the same job.

Both of the approaches have advantages and disadvantages. It s obvious that the network should be layered and distributed.
A Grid-enabled Multi-server Network Game Architecture paper, indicates
a new approach using gamelets on Grids which is pretty cool. I would use that one.

References :
A Grid-enabled Multi-server Network Game Architecture

http://i.cs.hku.hk/~clwang/papers/Gamelet-submitted-02-24-2004.pdf

Layered Game Architecture

http://bnrg.eecs.berkeley.edu/~randy/Courses/CS294.S02/White2.ppt

Comparison of the use of Amazons EC2 and Windows Azure, cloud computing and implementation of Map-Reduce.

Juan G Diaz

Brooklyn College

The City University of New York

http://juangdiaz.com

Cloud Computing has been accepted globally as a one stop shop for dynamically scalable and resources that are virtualized as services over the internet. They can virtually “Out-Source” their infrastructure and concentrate in their development. These third-parties would take care of these services and will provide the computing power as needed.  In which key companies have been exploiting the use of it and taking advantage of making profit at the same time creating new tools for programmers to work with.

These companies however provide different sets of tools for programmers to work with, one takes the open source route, on the other hand the other company takes the advantage of close source and very limited to the use of other non-proprietary software

Amazon EC2

Amazon provides Amazon Elastic Compute Cloud (Amazon EC2), which presents a virtual computing environment. Users can launch instances of a variety of operating systems; enabling them to access them as a web service, loading them with custom application environments and enabling them to create multiple images of the software instances as needed with the same configuration.

Amazon EC2 includes a vast amount of web services in which they are market as Amazon Web Services (AWS), they are: Alexa Web Services, Amazon Associates Web Services, Amazon AWS Authentication, Amazon CloudFront, Amazon DevPay, Amazon Elastic Block Stores, Amazon SimpleDB, Amazon Elastic Map Reduce, among others [1].

It offers flexible environment to the user, is as simple as creating your own virtual machine with your own configuration and upload it to their platform. Also you can use their predefined virtual machines, or use other OSs from a community based selection in which they have many different configurations. Since this is the case it can run virtually in any programming language and any OS flavor. Though, the use of Amazon Elastic Map Reduce is restricted to several programming languages, in which I will be discussed later on [2].

Microsoft AZURE

Microsoft offers a similar product called Windows Azure Platform, which is a form of a Virtual computing environment and offers development services. It uses the Windows Azure Operating system, which means that it would only run under a windows server like operating system and there is no support for Unix/Linux type of operating systems. This operating system is enhanced to take the advantages of being on a cloud, designed for high availability and dynamic scaling to mach users needs.

This platform includes five services:  Live Services, SQL Services, .NET Services, SharePoint Services and Dynamic CRM Services [3] – which are the tools used by developers to build applications over the Azures cloud. These services would be provided by adding to the Visual Studio a Library that manages the use of the Azure platform.

Azure currently runs on the Microsoft Visual Studio Environment and the .NET Framework, supporting the use of ASP.NET applications and provides the associated methods to deploy on to the cloud.  The use of 3rd party software or open source is very limited as of this moment, but allows some of the most popular tools and languages such as Eclipse, Ruby, PHP, and Python [4].

Cloud Services Comparison (Map-Reduce)

When it comes to cloud services we need to compare the most important tools that are used in distributed computing systems on large data sets in a cluster of computers. One of this tools is Map-Reduce which is a software framework introduced by Google [5].  It is created from the map and reduce functions that are commonly used in Functional Programming [6], that has been tailored to be use in large data set in cluster systems.

Map-Reduce functions work as a (key, value) pairs:

Map takes one pair of data with a type with a data domain, and returns a list of different domain.

Map (k1, v1) à list (k2, v2)

The production of list (k2, v2) pairs calls gets grouped together, thus creating one group for each one to the different generated keys.

Reduce is applied after the Map which in turn it processes a collection of values in the same domain.

Reduce (k2, list (v2)) à list (v3)

Each return will produce either one value for v3 or empty, then the desired return call aree collected as a result list.

* http://aws.typepad.com/aws/2009/04/announcing-amazon-elastic-mapreduce.html

Apache Hadoop [7], was inspired by Google’s Map-Reduce [5], it’s a Java based that’s supported to provide data-intensive applications over a cluster system.  Amazon presents Amazon Elastic Map Reduce, as a web service that offers businesses, researchers, data analysts and developers a cost effective an easy to use that process vast amounts of data [2]. Amazon adopted this open source project instead of creating its own version of Map-Reduce. It was a wise decision since its Java based and its widely used and combining this with their infrastructure of Amazon Elastic Compute Cloud (EC2) and Amazon Simple Storage Service (Amazon S3).  Amazon uses the term Elastic, which is centered on the concept of job flow. Each job flow can use data from Amazon’s S3, and distributes them to an specify number of EC2 instances running Hadoop (as many Virtual instances)

On the other hand Microsoft Azure doesn’t have any real capabilities to control virtual clusters programmatically.  There have been some attempts to create an answer to Map-Reduce over a cloud. Moreover, Microsoft is still in its Beta version of their cloud and they have been expanding and changing their technologies.

One of them is called DryadLinq, it’s a research done by Microsoft. As stated in their website it’s a simple, powerful and elegant programming environment for writing large scale data parallel applications running on a large PC cluster [8].  Dryad is an infrastructure which allows a programmer to use the resources of a computer cluster or a data center for running data-parallel programs. A Dryad programmer can use thousands of machines, each of them with multiple processors or cores, without knowing anything about concurrent programming. [8] DryadLinq combines the power of the Dryad distributed execution engine and the power of the Language Integrated Query (LINQ), makes distributed computing easier to distribute parallel applications in thousands of clustered computers.  Hence, this is a great tool created by Microsoft, DryadLinq is only targeted to cluster environments, which it’s different from a cloud computing environment which make is difficult to port it to Microsoft Azure.

There is also another interesting attempt to reproduce Map-Reduce, there is an open source application that does this, it just started a couple of month ago but it’s still in its infancy steps. But it looks very promising; this is located in Google’s codeplex open source website, called MapSharp [9]. Unfortunately there is not enough information at this time to tell us more about this project.

Comparing both Amazon and Microsoft, indeed Amazon has the advantage of being in the market for a longer period of time. Thus Amazon taking the advantages of open source it was easy and cost effective to include Hadoop into their array of web services for the cloud. Conversely, Microsoft still has a long route ahead of them, but it is very promising for the .NET world, their tools makes an easy access to the cloud by just adding a Toolkit to the Visual Studio IDE and some limited access to other programming languages. However, they will have some trial and error before they have a solution to Map-Reduce functionality could be delivered to Windows Azure

1. Amazon Web Services (AWS)

(http://aws.amazon.com/products/)

2. Amazon Elastic Map Reduce

(http://aws.amazon.com/elasticmapreduce/)

3. Microsoft Azure

(http://www.microsoft.com/azure/)

4. Microsoft Azure (What is Azure)

(http://www.microsoft.com/azure/whatisazure.mspx)

5. Map-Reduce: Simplified Data Processing on Large Clusters

(http://labs.google.com/papers/mapreduce.html)

6. Map Reduce

(http://en.wikipedia.org/wiki/MapReduce)

7. Apache Hadoop

( http://hadoop.apache.org/)

8. Microsoft Research of Map-Reduce-DryadLinq

(http://research.microsoft.com/en-us/projects/dryadlinq/default.aspx)

9. Google CodePlex – Map-Reduce using Mapsharp

(http://mapsharp.codeplex.com/)

c# checked and unchecked blocks

You can use checked and unchecked blocks to throw or suppress exceptions while converting between data types.

checked{

int max = int.MaxValue;

max = max + 1;

Console.WriteLine(max);

}

Above code will throw an exception, while the below code surpress the exception but prints an overflowed value.

unchecked{

int max = int.MaxValue;
max = max + 1;

Console.WriteLine(max);

}

This will print a funny number, a negative number. But doesnt throw an exception.

Empty catch block is designed to catch any unhandled exceptions.

public void aFunction(){

try
{

// …

}
catch
{
// Any unhandled exception

throw;

}

}

in exception hierarchy, catch block is in the highest hierarchy. This is called General Catch Block.