Monthly Archives: April 2017

Prevent A Same SSRS Report From Running Concurrently

Some report could have quite long run more then some minutes. Usually due to heavy query or big content.
This blog will show how to prevent a specific SSRS report to have two or more report instances being run in same time.
So it applies only to each report you want to validate.

Creating Class Library

First, you need to make a class library either using VB.Net or C# and add a Web Reference to SQL Server Reporting Service API.
This class library is intended to list all active SSRS report jobs.

  1. Create a VB.Net Class Library Project and save it as SSRSLib.vb
  2. Add Reporting Service Web Reference.
    To do that, click Add Service Reference, Advanced, Add Web Reference.
    Inside Url text box type http://yourServIpAddr/ReportServer/ReportService2010.asmx for SSRS 2008 R2 version, click ‘go’ arrow icon.
    Edit the Web Reference Name to your prefer i.e ReportService2010 and then click Add Reference button.
  3. Write a class to retrieve list of SSRS Active report jobs
    Public Class SSRSInstance
    Public Sub New()
    
    End Sub
    Public Function getJobs() As DataTable
    	Dim dt As New DataTable()
    	dt.Columns.Add("JobID")
    	dt.Columns.Add("Name")
    	dt.Columns.Add("ComputerName")
    	dt.Columns.Add("UserName")
    	dt.Columns.Add("Action")
    	dt.Columns.Add("StartTime")
    	dt.Columns.Add("Status")
    
    	Dim rs As New ReportingService2010()
    	rs.Credentials = New System.Net.NetworkCredential("yourUserId", "yourPwd")
    	Dim jobs As Job() = Nothing
    	jobs = rs.ListJobs()
    
    	Dim job As Job
    	Dim dr As DataRow
    	For Each job In jobs
    		dr = dt.NewRow()
    		dr("JobID") = job.JobID
    		dr("Name") = job.Name
    		dr("ComputerName") = job.Machine
    		dr("UserName") = job.User
    		dr("Action") = job.JobActionName
    		dr("StartTime") = job.StartDateTime
    		dr("Status") = job.JobStatusName
    		dt.Rows.Add(dr)
    	Next job
    
    	Return dt
    End Function
    End Class
    
  4. Build your project. Since my assembly named SSRSLib so that build project will produce two dll files which are SSRSLib.dll & SSRSLib.XmlSerializers.dll
  5. It is better to test your class Lib with Console Application before proceeding any further to know whether it contains error or success

Okay first step has done. The SSRS list jobs class library is created. Usually the class library created for SSRS called custom assembly.
Continue reading

Multi Tier PHP Application Using RabbitMQ, Web & Worker Architecture

Large Web application needs to have some strategy to ensure web run smoothly. It is also intended to avoid Server down on busy hours.

Imagine thousand to million hits your Server simultaneously. Application could be down even with great hardware specs.
In Hardware point of view, you can do Load Balancing, Traffic Manager, Scale out by adding more Virtual Machine or Scale in by getting higher specs i.e CPU, Memory, HD.
The infrastructure setup is even easier using popular Cloud Portal available widely in market i.e Ms Windows Azure, Amazon Web Service, Google Cloud Platform.
You don’t need to have physical servers on your room. Cloud Portal has menu to create VMs and there are several CPU, Memory, Storage specs options. More high the specs then more costly.
Also you can do Load balancing, Auto/Manual Scaling, Traffic Manager with just some clicks on the Portal.

However considering only H/W and infrastructure sometimes is not enough.
You don’t want to be forced urgently to add more VM or increase H/W specs just because actually you are not managing your application or software properly.

Modern enterprise application use Multi Tier architecture. They use Web and Worker tier for handling users request. On back end side there are database and storage tier.
Web tier contains user interface i.e html body, event handler, etc. Worker is a background process that continuously run and usually used to process jobs which require more computational resources asynchronously .
The main purpose to have web & worker tier is to avoid requests burden application too busy and further more causing your server not responding.

Lets say we have an incident example. There is a web app which has reporting feature sent to user in PDF format. Many clients request for reports simultaneously and those requests are directly processed by database server on same time.
Also after data is retrieved, the Web tier creating many PDF based on requests and send them to clients by email.
Slowness will occur and thus Server either web tier or database will not responding. Not to mention if web tier and database is in one VM only.
You need to stop requests by killing them or just restart the server.

This case is a good example for explaining the need of Worker. So Web tier will sent user request by writing a message to Message Queue instead of sent requests directly to back end or database tier.
Message Queue is just text stored in a Message broker and it has FIFO (First In First Out) for write & read those messages. In this scenario, Web Tier write a request as message to Message Queue
Worker instance that run continuously on background reads client request or message from Message Queue and creating PDF report. The PDF report creation will be sequential based on FIFO of message queue.
So only one report processed in a time for one Worker instance. Lets say you want more report generated in time then you can generate another Worker instance. So you have two or more Workers.
You can manage how many workers you can have based on Server performance.

After Report is generated either that Worker which auto send the report or you may create another Worker to do it.
So first Worker that generate report will write a message to Queue when report is done. Second Worker read a message and send the report.

Below is the schema of multi tier application with Web & Worker Tier.

It is a common scenario and also as a tutorial example in internet since it is understandable with ease.

However this blog post source code is not presenting above schema.
This time we assume for having a Photo Web App and it has more than thousands hits every day like Instagram. This example will retrieve list of photos of followed persons / owner.
Since the Web app hits is quite heavy then we need some strategy using multi tier application.

Basic method to retrieve an image is to download it from database via Web tier and show it to browser. We won’t do that way. We will use Worker to retrieve photos from DB and store them to file storage.
Web tier will show those photos to client browser. The communication between Web & Worker tier use Message queue i.e RabbitMQ.

Please look the schema below:

The difference for this case is the Message Queue has ‘reply-to’ feature. So every request will be replied through Message Queue to ensure Web tier (client) get response immediately after photos are generated.

Many Message Queue available on internet but I use RabbitMQ because of easiness to install and easy to code also.
If you have not familiar yet with RabbitMQ then I suggest you to go to this Url: https://www.rabbitmq.com/getstarted.html and install it to your PC/laptop/dev server.
There is also nice step by step tutorials so you can go through it.
Continue reading