Friday, October 24, 2014

Send your Name to Mars!

Mission to Mars!
Just kidding..

Add your name to the list created by NASA and it will be sent to the Mars upcoming launch!

Tuesday, April 10, 2012

My First Photo shop work

My First Photo shop work!!!



                I always had thirst to work on photoshop to edit our own photos and make the photos much brighter, sharper and colorful as if the photo was taken in DSLR camera which had 24-70 f2.8 lens (Even though I just own a Nikon Coolpix Point and shoot Digital Camera now :P )
So after years and years of thinking finally I thought to download Photoshop elements 10 software (which is the latest version on the net) from Photoshop website and end up with a torrent which I got the full dump :) horray!!!
I installed Photoshop elements 10 on to my new HP laptop last week and was doing small tasks like cropping, red eye fix, apply healing brush etc.. and today I finally got a task to do. when I was applying a credit card through online I came across a option to choose your card design. Can you believe it? In US you can simply select your own card design by uploading a wallpaper into the credit card portal and they will simply apply the whole image as a background of your credit card with no additional cost. Wow that is so nice of them..

Anyway coming back to our task, I thought instead of uploading a existing wallpaper (they already had lots of wall paper in their website to choose one or you can upload your own wall paper from your computer) why can't I just create my own wall paper with a colorful background and my picture as the foreground. Yes you got it. (This is how legends are born!!! :P I'm not saying im a legend) I took a colorful wallpaper,
 and one small puppy photo


and a recent photo of Me to start the work.

After seeing few photoshop tutorials to how to cut a photo using photoshop tools and paste and make it real, I got the final output


I went on to put lot of effort to make me to fit into that greeny wallpaper as my photo was whiteish ( that photo was took in a cloudy snow day).  Even though the modified photo didnt had that professional touch and work it was ok for me to upload into credit card website for my First Creditcard in US. Here is how my creditcard is going to be after it is dispatched.
  

Wednesday, June 22, 2011

Google Translater for Indic Web ( Tamil, Telugu, Kannada, Gujarati, Bengali)

Google now translates in our mother tongue too.. Sounds familiar but there is a new stuff added to the translater complier. yes, the translater actually tries to get the meaning of a word instead of simply converting a word from one language to other...

For example, If you want to convey "thanks" to a tamilian and you know only english. Now its not a problem. Just use google translater and now it translates and finds the exact tamil word for "thanks" from its tamil dictionary. Sounds interesting right? I tried few words to translate and it works.. but still google still holds this in "alpha" version as it couldn't convert a whole sentense from english to Indic languages. The reason is Indian languages often use Subject Object Verb (SOV) order unlike English, which uses Subject Verb Object (SVO) order. see the picture below



More details about Google translator check Indic Web and the URL for you to test the same.

Tuesday, August 10, 2010

WCF Architecture

The following figure illustrates the major components of WCF.

Figure 1: WCF Architecture

Contracts

Contracts layer are next to that of Application layer. Developer will directly use this contract to develop the service. We are also going to do the same now. Let us see briefly what these contracts will do for us and we will also know that WCF is working on message system.

Service contracts

- Describe about the operation that service can provide. Example, Service provided to know the temperature of the city based on the zip code, this service we call as Service contract. It will be created using Service and Operational Contract attribute.

Data contract

- It describes the custom data type which is exposed to the client. This defines the data types, are passed to and from service. Data types like int, string are identified by the client because it is already mention in XML schema definition language document, but custom created class or datatype cannot be identified by the client e.g. Employee data type. By using DataContract we can make client aware that we are using Employee data type for returning or passing parameter to the method.

Message Contract

- Default SOAP message format is provided by the WCF runtime for communication between Client and service. If it is not meeting your requirements then we can create our own message format. This can be achieved by using Message Contract attribute.

Policies and Binding

- Specify conditions required to communicate with a service e.g security requirement to communicate with service, protocol and encoding used for binding.

Service Runtime

- It contains the behaviors that occur during runtime of service.

  • Throttling Behavior- Controls how many messages are processed.
  • Error Behavior - Specifies what occurs, when internal error occurs on the service.
  • Metadata Behavior - Tells how and whether metadata is available to outside world.
  • Instance Behavior - Specifies how many instance of the service has to be created while running.
  • Transaction Behavior - Enables the rollback of transacted operations if a failure occurs.
  • Dispatch Behavior - Controls how a message is processed by the WCF Infrastructure.

Messaging

- Messaging layer is composed of channels. A channel is a component that processes a message in some way, for example, by authenticating a message. A set of channels is also known as a channel stack. Channels are the core abstraction for sending message to and receiving message from an Endpoint. Broadly we can categories channels as

  • Transport Channels

    Handles sending and receiving message from network. Protocols like HTTP, TCP, name pipes and MSMQ.

  • Protocol Channels

    Implements SOAP based protocol by processing and possibly modifying message. E.g. WS-Security and WS-Reliability.

Activation and Hosting

- Services can be hosted or executed, so that it will be available to everyone accessing from the client. WCF service can be hosted by following mechanism

  • IIS

    Internet information Service provides number of advantages if a Service uses Http as protocol. It does not require Host code to activate the service, it automatically activates service code.

  • Windows Activation Service

    (WAS) is the new process activation mechanism that ships with IIS 7.0. In addition to HTTP based communication, WCF can also use WAS to provide message-based activation over other protocols, such as TCP and named pipes.

  • Self-Hosting

    WCF service can be self hosted as console application, Win Forms or WPF application with graphical UI.

  • Windows Service

    WCF can also be hosted as a Windows Service, so that it is under control of the Service Control Manager (SCM).

Tuesday, April 27, 2010

Processing Data Queues in SQL Server with READPAST and UPDLOCK

Problem
One common processing problem that a DBA can encounter is processing rows from a table used as a data queue. Queue processing is functionality where one or more processes INSERTs rows into a database table representing a work queue with each row representing a business action that must be performed. At the same time, one or more processes SELECTs records from the same queue table in order to execute the business action required by the application while later deleting the processed row so it is not processed again. Typically, the reading processes use polling to interrogate the queuing table for any new rows that require execution of a business action. If done incorrectly, processing data queues can produce unexpected results and/or performance issues.

Solution
The following examples set up a process queue to be processed by two separate processes reading the same queue. This can be extended beyond two processes, but for this example we want to show you how two processes can work against one work queue. We’ll start with examples to illustrate issues that can be encountered.

First, let’s create a sample table and populate it with 10 records to be processed.

-- create an example queue table
CREATE TABLE DBO.QUEUE (
QUEUEID INT IDENTITY( 1 , 1 ) NOT NULL PRIMARY KEY,
SOMEACTION VARCHAR(100))

GO

-- seed the queue table with 10 rows
DECLARE @counter INT

SELECT
@counter = 1

WHILE (@counter <= 10)
BEGIN
INSERT INTO
DBO.QUEUE
(SOMEACTION)
SELECT 'some action ' + CAST(@counter AS VARCHAR)

SELECT @counter = @counter + 1
END

Encountering unexpected results
Open 2 separate query windows and issue the following statements in each session:

DECLARE @queueid INT

BEGIN TRAN
TRAN1

SELECT TOP 1 @queueid = QUEUEID
FROM DBO.QUEUE

PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)

-- account for delay in processing time
WAITFOR DELAY '00:00:10'

DELETE FROM DBO.QUEUE
WHERE QUEUEID = @queueid

COMMIT

As you will see, each session processed the same row! This is obviously unacceptable processing behavior, but what can we do about it?

We can eliminate this behavior by adding the UPDLOCK hint to the SELECT statement. The UPDLOCK hint tells the SQL Server query engine “Don’t allow any other reader of this row to acquire an UPDLOCK (“U” lock) because I will be promoting this lock to an exclusive “X” lock later in my processing”. It effectively reserves the row for your processing. However, as you will see, this can cause a new problem to arise.

Encountering blocking
The SELECT statement has been modified to use the UPDLOCK hint.

Open 2 separate query windows and issue the following statements again.

DECLARE @queueid INT

BEGIN TRAN
TRAN1

SELECT TOP 1 @queueid = QUEUEID
FROM DBO.QUEUE WITH (updlock)

PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)

-- account for delay in processing time
WAITFOR DELAY '00:00:10'

DELETE FROM DBO.QUEUE
WHERE QUEUEID = @queueid

COMMIT

As you can see from the modified example, each session now processes separate rows. Good so far. However, the 2nd session took longer to execute than it did in the first example even though it now processes a separate row. Why is this? It’s because an UPDLOCK (“U”) lock has been placed on the row processed by the first session and the 2nd session is forced to wait on this lock to be released before it is allowed to retrieve the next row for processing. This is highly inefficient since multiple consumers of the queue must all wait until any locks are released. So, how do we get around this?

To get around the blocking encountered in the previous example, a READPAST hint can be used in conjunction with the UPDLOCK hint. The READPAST hint tells the SQL Server query engine “If you encounter any rows that are locked, just skip them… I want whatever is not currently being processed by anyone”.

Incorporating the READPAST query hint
The SELECT statement has been modified to use the READPAST hint in addition to the UPDLOCK hint.

Open 2 separate query windows and issue the following statements again.

DECLARE @queueid INT

BEGIN TRAN
TRAN1

SELECT TOP 1 @queueid = QUEUEID
FROM DBO.QUEUE WITH (updlock, readpast)

PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)

-- account for delay in processing time
WAITFOR DELAY '00:00:10'

DELETE FROM DBO.QUEUE
WHERE QUEUEID = @queueid

COMMIT


As you can see from this latest example, each session now processes separate rows and the 2nd session is no longer blocked as evidenced by the execution time (both sessions should complete at roughly the same time).

Using the UPDLOCK hint in conjunction with the READPAST hint gives the best performance for processing queues while eliminating unexpected results and blocking.

Putting it all together
Here is an example of the above code that takes it a step further and processes all of the records in the queue. To run this drop table dbo.queue and then recreate it by running the code in the very first code block above that creates the table and loads the data.

Open 2 separate query windows and issue the following statements again.

SET NOCOUNT ON
DECLARE
@queueid INT

WHILE
(SELECT COUNT(*) FROM DBO.QUEUE WITH (updlock, readpast)) >= 1

BEGIN

BEGIN TRAN
TRAN1

SELECT TOP 1 @queueid = QUEUEID
FROM DBO.QUEUE WITH (updlock, readpast)

PRINT 'processing queueid # ' + CAST(@queueid AS VARCHAR)

-- account for delay in processing time
WAITFOR DELAY '00:00:05'

DELETE FROM DBO.QUEUE
WHERE QUEUEID = @queueid
COMMIT
END

Next Steps

  • When processing data queues, use the UPDLOCK hint along with the READPAST hint to get maximum throughput of your data queues.
  • Read more information about UPDLOCK and READPAST in the SQL Server 2000 and 2005 Books Online under Locking Hints.
  • Read more about Lock Compatibility in the SQL Server 2000 and 2005 Books Online
  • Thank you to Armando Prato for providing this tip!