Thursday, June 26, 2014

If you have worked extensively on nhibernate then you will understand the caveat it carries at time of implementation. One of the case is with foreign key constraint for one to many relationship in which it fails to insert rows for child as it always sends foreign key column value zero and when it tries to apply this it into constraint-data integrity conflicts.

Most of the solution suggests:-
1. Apply Inverse =true
2. Apply Cascade all

So on..

But all this solution doesn't work.

When one remove foreign key constraint it works absolutely fine. What it does under the hood?

1. It first insert the parent table enteries.
2. It then insert the child table enteries but keep the foreign key column value as zero
it tries to apply select scope_identity but it return null.
3. Then there are two update on parent and child table where it just update foreign key column with actual values.

The above step is tricky to understand but can be evident in sql profiler log.

Workaround- You can keep the foreign key but can disabled constraint( Disabled Constraint does not mean removing constraint) It still satisfy DDL best practice.

Wednesday, June 25, 2014

Parallel Connection-
Initially it is like one user agent-web browser can establish two connection with host webserver. Just imagine we have two files that needs to be requested therefore browser makes two requests and establish two connection to download the files.

IE6 used to have this 2 connection setup.

* Approach 1:

We keep files in different server in that case user agent can opens parallel connections to host server. In that sense, we states two connections is directly proportional to host and not IP addresses of the host. So we conclude two connection is dependent on host but independent of IP address.

* Approach 2:

With case of IE8 where it applies heuristics logics and it establish 6 concurrent connections w.r.t host.

Persistent Connections:-

Connection: keep-alive

This is a state where we keep the socket opened or maintain persistent connection even it server one request response transaction for given user agent. It persist the connection between user agent and host and consume same socket opened for communication. With this there is no overhead on memory consumption, cpu utilization, less network congestion, less latency, more throughput and improves response time of given request.

The only demerits about this type of connection is falling prey of security vulnerability. Longer period of open connections can pose threat to security compromise. Some webserver close connections when idle even we can configure
user agent or webserver to close connection when idle for certain threshold limit.

HTTP/1.1 200 OK
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NETConnection: close
This close header indicates that connection will be closed as soon request is served with response and hence no subsequent request on same socket is available.Pipelined Connections-

It opens up multiple connections and queue the requests into efficient packets. But this is not widely used.

Is very much visible to end users. It takes users http request and take response back from server to the user.

Benefits of Proxy Server-1. In order to prevent users accessing restricted sites we can use proxy server to capture all http traffic at proxy server and thus setup strategy that will not send these requests to destination server. In this way we can ensure no one use the sites that is restricted.

2.Proxy server in fact can be used to inspect /probe the confidential message flow from system to server. In a way we can remove referrer headers that referenced organization resources such as images, files etc.

3. Proxy server can acts as access control to create http log that act as audit trail for http request that is send.

Type of Proxy

Forward Proxy Server-

This server sits close to client. This proxy help secure confidential information and can help filter traffic send from the client to destinations server.

Reverse Proxy-

is a proxy server that sits close to the server.This server can take off the load from destination webserver or any server for that matter. Take a case of compression of file or data using gzip which can delegated to this proxy server making destination server concentrate on processing of data or request.

Load Balanaced Proxy server-

All http request reaches this load balanced proxy server which will send requests to given server based on load as per round robin manner.

SSL Acceleration server-

This server will encrypt and decrypt http messages. This provides very secured level of isolation and can act as a centralized source to provide insulation to attack such as cross site scripting (XSS) or sql

injection for that reason.

Caching proxies-

Can act as centralized repository of cached data in distributed environment.

Caching -

HTTP response can have a value for Cache-Control of public, private, or no-cacheThere is also a no-store value, meaning the message might contain sensitive information and should not be persisted, but should be removed from memory as soon as possible.

Public Cache- This is cache is applicable to whole system and is available for all users. Say for e.g we have logo, header and footer which will be consistent for all users.

Private Cache- This cache is specific to users , we can use Response.Cache for this kind of caching.

EtagThere are other ways to even identify given resource has been changed from last cache value is Etag. Etag is hashed values. Every time resource value or resources data changes it generated new hash value. Using this identifier we can even check the cache nature of the data.

Tuesday, June 24, 2014

In part 1 , I almost listed most of the intrinsic feature of Http. In part 2, the focus is more on how http interact with other layer protocol and ensure connectivity and communication.

Courtesy Succinctly Http: By Scott Allen

1. Http :it allows two Web Browser and Web Server( IIS or Apache) to communicate over a network.
2.TCP- Transmission Control Protocol

Browser extract host name and port . Opens TCP socket. Once ports is data is written into the socket.
TCP ensures data is transmitted to server and notify error if any. TCP also controls the flow of data, it has mechanism where it controls the rate at which that data being transfered thus ensuring enough time for receiver to process the data. Flow control is two way handshaking that TCP very well follows. Hence TCP is reliable protocol with flow control and error detection
mechanism.

3.IP: Internet protocol:-
IP ensures data moves across switches, routes, gateways , repeaters and other devices that help flow of data. IP even breaks down the larger piece of information into packets-fragment called data datagrams. This is indeed optimizes performance over network segment.

URL with keyword such as author is help rank your website for given search keywords in URL.It improves your Search Engine Optimization.

By default URL with out port points to port 80. Other than port 80, one needs to mention or host url with port number.

#sign represents fragment. The fragment locate a specific HTML element in a html page by control ids. For example bookmark in given page.

URL EncodingUnsafe characters such space and ^ carat are replaced with %%20 is the encoding for a space character ( 20 is hexadecimal value = US-ASCII space character).%5 represents ^Resources and Media
Web page can request different resource format for display for end users they can be executable applications ,mages, XML , Json,video,HTML audio etc.
When a host server responds to an HTTP request, it returns a resource and also specifies the content type. This content type is called Media type. Media type is represented by Multipurpose Internet Mail Extensions (MIME) standards.
Client request content type html then it will send text/html
Similarly
"image/jpeg""image/gif""image/png"

File Extension in URLFile extensions not always output requested file extension as given example http://something.com/main.jpg
How it works:-
1. Client first look at response header content type tag send by host server.
2. If content type not available it will parse first 200 bytes of response to identify content type.
3. If client fails to identify content type and first 200 bytes of response then it look into URL file extension to guess content type.

Content Type NegotiationClient can tell host server what content type it want at time of response. For example some resource of book url may suggest the client may display book content in some specific language and can be downloaded in specific format.In such scenarioncontent type negotiation plays a essential role.Accept keyword in Response header suggests this.Accept-Language: fr-FRHttp Request Method

Thursday, June 12, 2014

The above code is referenced from Bill Wagner post. The intent is the base constructor get called first and which indeed called Vfunc of derived class as in runtime the derived class had to be initialized.

Wednesday, June 11, 2014

Some Background Exception Handling (Task Parallel Library)

If a task is the parent of attached child tasks, or if you are waiting on multiple tasks, then multiple exceptions could be thrown. To propagate all the exceptions back to the calling thread, the Task infrastructure wraps them in an AggregateException instance

Problem Statement:

Most of the time when we create a unit testing on Async Method- TPL it executes the unit test completely but ends up throwing AggregateException. This is due to the fact that it completes the one set of flow completely within a thread and comes out without executing all thread in parallel. If you see there is no UI and hence while testing the TPL must understand that unit testing is just to check the conditions of expected output with actual given a input as required whereas TPL works in different context. So ideally we must create test on non TPL methods in such case create separate methods to test on.

•An asynchronous method call will either produce a result immediately if one is available and continue execution in the current method or it will produce a result at a later time and immediately return control to the caller of the current method.
•The code that comes after an awaited method – the continuation – is what will be executed when the awaited method returns with a result.http://www.jayway.com/2012/10/07/asyncawait-in-c-a-disaster-waiting-to-happen/

Workaround:

Brute force method not recommended but can be used if just unit test case conditions with failed and pass data.[TestClass]
public class TestAsyncClassTest {
[TestMethod] [ExpectedException(typeof(AggregateException))]
public void SomeAsyncTest() {
}
}

Monday, June 2, 2014

The data in dataware house keep growing day by day , data processing in data mart sometimes becomes unmanageable. The larger point is performance and to keep things at its bench mark we need proactive setup therefore Column Store Index is one of the important facility we can use in table to speed of query performance.