Friday, September 06, 2013

Scaling : Horizontal and Vertical Scaling

Recently I came across the term Horizontal and Vertical scaling of infrastructure. Though I am aware about the scaling but I couldn't differentiate differences between these two scaling. After some googling these are difference between these two scaling.

Horizontal Scaling
  • It also described as Scale-out.
  • In Horizontal scaling, additional nodes / computers will be added for scaling.
  • Due to low cost in hardware and introduction of VM, now people are moving towards it.
  • One of the main downside of Scaleout option would be latency and maintenance hardware.
Vertical Scaling
  • It also described as Scale-up.
  • Adding of memory / CPU to a server is called as Vertical Scaling.
  • Downtime is required during the up gradation.  


References
http://en.wikipedia.org/wiki/Scalability#Horizontal_and_vertical_scaling

http://pic.dhe.ibm.com/infocenter/brdotnet/v7r0m2/index.jsp?topic=%2Fcom.ibm.websphere.ilog.brdotnet.doc%2FContent%2FBusiness_Rules%2FDocumentation%2F_pubskel%2FRules_for_DotNET%2Fps_RFDN_Global478.html

Monday, June 11, 2012

Security Series: Session Hijaking / Cookie Stealing

ASP.Net identifies users by means of session ID Cookie [ASP.Net_SessionID].  In case of form authentication it uses additional cookie called .ASPXAUTH.
   
    If an attacker get these cookies then they can impersonate as valid user. Eventhough modern browser restrit to alter these cookies if you access it from differnt site but if the attackers is able to inject the script in our page then they will gain the access to these cookies.
   
This attack can be prevented be these methods
Client IP Address Check:  
Track the client IP address on which the session has been initiated. Deny if the request if the client IP address is different from the initiated IP address. 
       
    Even though this is nice solution but it suite for corporate LAN scenario but not suitable for Internet application. It will reject the client request in these scenarios
        * Connection has been reset and client go new IP Address.
        * ISP provider process all the HTTP through different set of load balance proxy server.
       
HTTPOnly Cookie: 
Mark a Cookie with HTTPOnly flag. This will hide the existance of the cookie to JavaScript but it will pass it with HTTP requests. Mark all the sensitive cookies as HTTPOnly ntill or unless you have a specific reason to access it through Javascript.
       
    By default ASP.Net marks both ASP.Net_SessionID and .ASPXAUTH cookies as HTTPReadonly. You can set it HTTPOnly as mentioned below
       
    Response.Cookies.Add(new HttpCookie("Cookie1")
    {
        Value = "Values",
        HttpOnly = true
    });
   
    It’s not a complete defense against cookie stealing, because you might still inadvertently expose the cookie contents elsewhere.


References
1. Pro ASP.Net MVC 3 Framework by Adam Freeman & Steven Sanderson
2. https://www.owasp.org/index.php/Session_hijacking_attack

Tuesday, June 05, 2012

Book: The Passionate Programmer

The Passionate Programmer by





Saturday, June 26, 2010

Inspiration

I am getting inspired by my kid.. She is 1 year old..
Whenever she watches new thing / animal / item. She gets excited and enjoy watching it.
But once got mature / grow old we start ignoring the new things instead we would satisfy with what we have.. And draw our own circle.

After watching her I have made resolution to explore new thing instead of ignoring it.

Saturday, May 16, 2009

Bubbling Exceptions in Threads

Bubbling the exception from the thread is altogether different from bubbling the exception.

In normal scenario, we will bubble the exception just by throwing the exception in the catch block, but if you do so in the multi thread applications these exceptions will be lost in transition.

public void Main()
{
try{
Thread MyThread = new Thread(new ThreadStart(ThreadMethod));
MyThread.Start();

MyThread.Join();
Console.Writeline("Completed Without Errors");
}catch (Exception ex){
Console.Writeline(ex.ToString());
throw;
}
}

private void ThreadMethod()
{
try{
Thread.Threading.Sleep(10000);
throw new Exception("Generated Error");
}
catch(Exception){
throw;
}
}

The exception generated in the ThreadMethod() won't be caught in the Main() catch block, rather it will print the statement "Completed Without Errors" in the console window. Because of the following reason, in the ThreadMethod() once the exception is generated and bubbled, but in the due course of time when it reaches the Main() method. Status of "MyThread" is completed and the it is removed from the memory.

Then, how to bubble the exception effectively to the calling program. In this case we need to assign the exception to the common variable and check the status in the Main() method.  



public class MyClass(){

Exception _ThrdMtdExp=null;

public void Main()

{
try{
_ThrdMtdExp =null;
Thread MyThread = new Thread(new ThreadStart(ThreadMethod));
MyThread.Start();
MyThread.Join();
if (_ThrdMtdExp!=null)
throw new Exception("Exception Raised by ThreadMethod()",_ThrdMtdExp);
else
Console.Writeline("Completed Without Errors");
}catch (Exception ex){
Console.Writeline(ex.ToString());
throw;
}

}

private void ThreadMethod()
{
try{
Thread.Threading.Sleep(10000);
throw new Exception("Generated Error");
}
catch(Exception ex){
_ThrdMtdExp = ex;
}
}
}

Now, the Main() method will capture the exception occured in the ThreadMethod().

Wednesday, May 21, 2008

Oracle Rownum Functionality in MySQL

In oracle we use the RowNum for various reasons. Here we are focusing on the usage of RowNum on Select statement.

In MySql Limit will be the alternate to the RowNum feature. Additionally it can be used along with the Update / Delete statement. Example for the Limit usage is
Select * from table order by column A LIMIT

Saturday, November 18, 2006

Find Locking Objects in Oracle

This article will be helpful to identify the objects which are locked, blocking locks and the exactly which row is locked in Oracle DB.

In order to execute these query you should have the select grant on the following Oracle System Tables
* v$session
* v$Locked_object
* v$lock


/* To Identify the Locking*/
SELECT a.object_name, a.owner object_owner,
decode(b.locked_mode, 0, 'None',
1, 'Null (NULL)',
2, 'Row-S (SS)',
3, 'Row-X (SX)',
4, 'Share (S)',
5, 'S/Row-X (SSX)',
6, 'Exclusive (X)', b.locked_mode) locked_mode,
b.session_id sid, b.oracle_username, b.os_user_name
FROM all_objects a, v$locked_object bWHERE a.object_id = b.object_id
ORDER BY 1

/* To Identify The Bolking Locks*/
select s1.username '@' s1.machine ' ( SID=' s1.sid ' ) is blocking ' s2.username '@' s2.machine ' ( SID=' s2.sid ' ) ' AS blocking_status
from v$lock l1, v$session s1, v$lock l2, v$session s2
where s1.sid=l1.sid
and s2.sid=l2.sid
and l1.BLOCK=1
and l2.request > 0
and l1.id1 = l2.id1
and l2.id2 = l2.id2 ;


/* To Identify Which Row is Locked*/
/* Replace the Tag <> with the appropriate SID*/
select row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row# from v$session where sid= <>;

/* To Identify Which Row is Locked*/
/* Replace the Tag <> with the appropriate SID*/
select do.object_name,
row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#,
dbms_rowid.rowid_create ( 1, ROW_WAIT_OBJ#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#, ROW_WAIT_ROW# )
from v$session s,
user_objects do
where
s.ROW_WAIT_OBJ# = do.OBJECT_ID
and SID=<>;

Friday, November 17, 2006

Transparent Background For User Controls on C#

Inorder to set the Transparent property to your user control,

Please add the following code in the Construtor of your code

// Setting the Control's Style Property
this.SetStyle(System.Windows.Forms.ControlStyles.SupportsTransparentBackColor,true);

//Set the Backcolor of the Property to Transparent
this.Backcolor=System.Drawing.Color.Transparent;