Blog Posts

Wednesday, December 22, 2010

WaveMaker for Cloud Applications in Java

My friend who was a Java Developer was very much interested in Cloud Development, while searching for the Cloud Application development tools/API.  Thought of forwarding to him - 


More on -
http://www.wavemaker.com/


http://en.wikipedia.org/wiki/Wavemaker


Few lines from wikipedia - 

WaveMaker (formerly known as ActiveGrid) is an open source software development platform that automates much of the process for creating Java web and cloud applications. WaveMaker provides a visual rapid application development platform and is available as a free open source software download or as a hosted cloud development environment (akaPlatform as a Service) running on Amazon EC2.[1]


From WaveMaker -



WaveMaker is the only open and easy-to-use development platform for web and cloud applications. With WaveMaker's visual, drag and drop tools, any developer can start building enterprise Java applications with minimal training. WaveMaker creates standard Java applications, boosting developer productivity and quality without compromising flexibility.
WaveMaker applications are cloud-ready and include built-in support for multi-tenancy and elastic scaling. WaveMaker is a rapidly-growing company backed by a 15,000-strong developer community. WaveMaker customers like the Center For Disease Control, Macy's and KANA have built rich internet applications with minimal learning curve and up to 98% less code.

Sunday, December 19, 2010

Grouping in LINQ

Grouping in LINQ provides flexibility and reliability over for loops while manipulating DataTable data.  As the LINQ uses the power of Generics, we can write code that avoid issues related to type conversion.  

I am taking a simple example explain the grouping LINQ, I am loading data from xml file (it is similar to getting data from SQL server).  I have to display the data by monthly and yearly.  My xml file has the content refer end of the post.

If I need to show the data by monthly in a grid (grdSales) on my form - 



DataSet ds = new DataSet();
ds.ReadXml("Sales.xml");


var sales = from r in ds.Tables[0].AsEnumerable()
group r by new { month = r["Month"].ToString(), year = r["Year"].ToString() } into grp                


orderby grp.Key.year, grp.Key.month
     select new SalesDetails
     {
        Year = grp.Key.year,
        Month = grp.Key.month,
        Sales = grp.Sum(s => Convert.ToInt32(s["Price"].ToString()))
     };


List<SalesDetails> lstSales = sales.ToList();

//adding total row
lstSales.Add(
sales       
      group r
(from r i n by sales into grpTotal
ails
      {
         Year =
      select new SalesDe t"Total",          Month = "",
=> s.Sales)
      }).ToList()[0]
     );
 
         Sales = grpTotal.Sum(
sgrdSales.DataSource = lstSales;



Sum() is the method from Enumerable class which is implements the the IEnumerable interface. refer the http://msdn.microsoft.com/en-us/library/system.linq.enumerable.aspx for other method of the class like Min, Max and Average.  These methods are overloaded to support datatypes like Int, Decimal etc.  And grp is the object of class which implements IGrouping.


Similarly to show data by year - 
DataSet ds = new DataSet();
ds.ReadXml("Sales.xml");
var sales = from r in ds.Tables[0].AsEnumerable()
    group r by r["Year"].ToString()into grp
    orderby grp.Key
    select new SalesDetails
    {
     Year = grp.Key,
     Month = "1",
     Sales = grp.Sum(s => Convert.ToInt32(s["Price"].ToString()))
    };


List lstSales = sales.ToList();
lstSales.Add(
      (from r in sales
       group r by sales into grpTotal
       select new SalesDetails
       {
        Year = "Total",
        Month = "",
        Sales = grpTotal.Sum(s => s.Sales)
      }).ToList()[0]
   );
grdSales.DataSource = lstSales;








One of the advantages of LINQ is, you can also have a List as one of the columns of your rows. As the following code populates a column with a List of month sales for the particular year.  






public struct MonthlySales
        {
           public string MonthName;
           public int MonthSale;
        }



var sales = from r in ds.Tables[0].AsEnumerable()
           group r by r["Year"].ToString() into grp
           orderby grp.Key
           select new SalesDetails
           {
              Year = grp.Key,
              monthSales =
                 (from rm in ds.Tables[0].AsEnumerable()
                   where rm["Year"].ToString() == grp.Key
                   select new MonthlySales
                   {
                     MonthName = rm["Month"].ToString(),
                     MonthSale = Convert.ToInt32(rm["Price"].ToString())
                   }).ToList(),
             Sales = grp.Sum(s => Convert.ToInt32(s["Price"].ToString()))
            };

The data populates like - 








My xml data from Sales.xml, and loaded data from database also should work.


<?xml version="1.0" encoding="utf-8" ?> <Sales>   <Sale><Item>item1</Item> <Price>2000</Price>  <Month>1</Month> <Year>2010</Year></Sale>   <Sale><Item>item2</Item><Price>3400</Price><Month>5</Month><Year>2010</Year></Sale>   <Sale><Item>item1</Item><Price>2200</Price><Month>7</Month><Year>2010</Year></Sale>   <Sale><Item>item1</Item><Price>1600</Price><Month>10</Month><Year>2010</Year></Sale>   <Sale><Item>item1</Item>  <Price>1200</Price> <Month>11</Month><Year>2010</Year></Sale>   <Sale><Item>item1</Item> <Price>500</Price><Month>12</Month>  <Year>2010</Year></Sale>   <Sale><Item>item1</Item><Price>2500</Price><Month>1</Month><Year>2010</Year></Sale>   <Sale><Item>item2</Item><Price>3400</Price><Month>5</Month><Year>2010</Year> </Sale>   <Sale><Item>item1</Item> <Price>2400</Price><Month>7</Month><Year>2010</Year></Sale>   <Sale><Item>item1</Item><Price>1600</Price><Month>10</Month> <Year>2010</Year></Sale>   <Sale><Item>item1</Item><Price>1000</Price> <Month>11</Month><Year>2010</Year></Sale>   <Sale><Item>item1</Item><Price>200</Price><Month>12</Month><Year>2010</Year></Sale>   <Sale><Item>item1</Item><Price>500</Price><Month>1</Month> <Year>2011</Year></Sale>   <Sale><Item>item2</Item><Price>3100</Price><Month>3</Month><Year>2011</Year></Sale>   <Sale><Item>item1</Item> <Price>2300</Price><Month>8</Month><Year>2011</Year></Sale>   <Sale><Item>item1</Item><Price>3400</Price><Month>11</Month><Year>2011</Year></Sale>   <Sale><Item>item1</Item><Price>2200</Price><Month>8</Month><Year>2011</Year></Sale>   <Sale><Item>item1</Item><Price>1200</Price> <Month>11</Month><Year>2011</Year></Sale>   <Sale> <Item>item1</Item><Price>2990</Price><Month>8</Month> <Year>2011</Year></Sale>   <Sale><Item>item1</Item><Price>1840</Price> <Month>11</Month><Year>2011</Year></Sale>   <Sale><Item>item1</Item><Price>1200</Price><Month>11</Month><Year>2011</Year></Sale>   <Sale><Item>item1</Item> <Price>6340</Price>  <Month>12</Month> <Year>2012</Year></Sale>   <Sale> <Item>item1</Item> <Price>9000</Price><Month>8</Month><Year>2012</Year></Sale>   <Sale> <Item>item1</Item><Price>1600</Price> <Month>9</Month><Year>2012</Year> </Sale>   <Sale> <Item>item1</Item><Price>1100</Price> <Month>7</Month> <Year>2012</Year></Sale>   <Sale><Item>item1</Item><Price>2300</Price><Month>8</Month><Year>2012</Year> </Sale>   <Sale><Item>item1</Item><Price>1800</Price> <Month>9</Month><Year>2012</Year></Sale>   <Sale><Item>item1</Item> <Price>1200</Price><Month>7</Month><Year>2012</Year> </Sale> </Sales>

Monday, December 13, 2010

Cloud Computing - Auto Scaling

Cloud Computing is going to change the way we compute, store data and present in our application. 


In the words of wikipedia - (http://en.wikipedia.org/wiki/Cloud_computing)


"Cloud computing is Internet-based computing, whereby shared resources, software and information are provided to computers and other devices on-demand, as with the electricity grid".
Auto Scaling enables the application developers to enable the resources added to the site/application at production when needed as according to the hits to the site,  http://blogs.msdn.com/b/gonzalorc/archive/2010/02/07/auto-scaling-in-azure.aspx, if my site is a success and the traffic is high it will be added with extra servers and storage to my site.  And if it is a failure I may need to pay only the lost cost for the single server or minimum resources.  Thus reducing risk of investment.


Came to know these are the sites which are already using cloud computing for their applications.
  • Zynga.com
  • NetFlix.com
  • Hungama.com
  • Animoto.com
And Microsoft is planning office suite 'Office 365' on cloud http://www.microsoft.com/en-in/cloud/default.aspx

One game site was a huge success and it just got from 80 servers to 3000+ server in a single night.  

OKEY, but what if I am not getting any revenue of my site and I want to restrict to only 1 (or few to fit in my budget) server? 
Simple I can set the Auto Scalling to off on my account of cloud computing.  Later I can use auto scaling when I am ready to invest.

Friday, December 10, 2010

Performance issue while Grouping in SSRS Reports

In one of our projects the report was taking too much time to load the report. When we analysed the issue we found that we are unnecessarily loading all the records into local reporting server when we need only top level data after applying grouping.
To explain this I am taking a simple example here but in real time there may be complex reports but with little analysis we can find the way to increase performance. Let’s take orders data, and we need to get a report of sales details that in various states.


When we write the query as below to get the details and apply the grouping in the SSRS report.

SELECT OrderID, State, Price, Product FROM SalesDetails

When there is more than 100,000 records in sales and when we run the report it will first fetch the 100,000 records to the report server and then applies the grouping. Assume if the network bandwidth is 1Mbbs it will take at least 10secs assuming each record of 100 bytes.
Instead of this we can use the grouping within the select statement to get only the required data –

SELECT State, Sum(Price), Count(1) FROM SalesDetails GROUP BY State

It will return only those number of records as sales.


But in real time tables may involve joins also. For those use nested select statements like –

SELECT t.State, Sum(t.Price), Count(1) FROM
( < your complex query with joins and other conditions > ) t
GROUP BY State


Lesson is to CONSIDER BANDWIDTH ALSO WHILE DEVELOPING REPORTS.