Analysing lock wait timeout – Blocking query vs Blocked queries

Hello buddies ! Hope you’ll are having good time with codes, coffee and monsoon. Same here 😛

Well, sharing a bit of technical gyaan (knowledge) from my last months experience. Considering here a well scaled application with multiple concurrent users trying to access its different functionalities. These functionalities may be using database for different CRUD operations and application being such huge, the database as well is expected to be huge with number of records in few tables being in millions.

There may be few cases wherein, multiple db queries from your application to your database would be querying / manipulating same table at a time. To handle such cases, the database engines (eg. ‘InnoDB’ – default MySQL engine) assigns locks on the tables/rows (depending on db operation) to the queries which are trying to access them. With this, if a query has taken lock on the table/rows, the db engine would stop allowing other db queries trying to use already locked tables. This way, the database engines tries to maintain data consistency.

Here, the query that is currently executing and has the lock is termed as ‘Blocking Query’ and all the other queries trying to access the already locked table, in other words, waiting for the blocking query to release the lock are known as ‘Blocked Queries’. So, there can be a possibility of having 1 Blocking Query and multiple blocked queries at any point of time.

The question here is ‘What will happen to the blocked query ?’
The queries fired from your application to your database would either be executing or be in blocked state. If blocked, the query would be waiting for some time (lock wait time) and if within that time, blocking doesn’t releases lock, the application would throw database exception stating lock wait time out.

The default lock wait time out for MySQL InnoDB engine is 50 seconds. This may be changed if required which would in turn reduce the chances of getting lock wait
time out issue. But this is not recommended, as you would not wish to have your web clients waiting for longer time and complaining you for poor application performance.

How do you know the reason for ‘Database exception stating lock wait time out’ ?
The reason is obvious, because your query waited for some threshold and was unable to execute because of a blocking query. But, you may also need to know, what was the blocking query that blocked the execution of a query which resulted to lock wait time out issue.

At any point of time, you may query your database’s metadata – information Schema to know what is/are the blocked queries and what is the blocking query. This would be helpful to know the current ‘Blocked Queries vs Blocking Queries‘.

Usually, in real time applications, you can’t wait for lock wait time out situation to happen and manually fire the query to find out Blocked Queries vs Blocking Queries right at that moment to find out the root cause. In short, in usual cases, the requirement is the analysis post lock wait time out has occurred. What would you do here ?

One option may be to have a batchjob / crontab that would keep firing the query to retrieve ‘Blocked Queries VS Blocking Queries’ from the information schema of
your database at every 30 seconds or say 1 minute. The retrieved value may be written in a table along with timestamp. Having this table with you, any time your application throws database exception stating lock wait timeout, you would be able the catch the culprit.

That’s all ! Tea break 😛


Some rundowns on Intent

1. What is an intent?

Intent comes from the word “Intention”. In Android, intents are used to communicate asynchronous messages between Android components, either from same application or from other applications.


  • An activity on interaction with user can request for another activity.
  • An activity of one app can request for taking pictures using inbuilt camera app of your phone.

The Intent class (android.content.intent) in Android is used to display and show our intentions.

We create an object of Intent, passing arguments what we want to do (moving from one activity to another) and pass it to ActivityManager. It will decide when to  start the activity.

Intents can be used to start activities, services, broadcast receivers.

2. How to request for another activity from one activity in code?

Intent has a lot of overloaded constructors.
Intent i = new Intent(source, destination)

source ⇒current context (MyActivity.this)
destination ⇒ requested class (NewActivity.class)

Intent i = new Intent(MyActivity.this, NewActivity.class);

Activities which are started by other Android activities are called sub-activities.

3. How to pass messages via intent in code?

An intent can pass data via Bundle.

Example: You want to send the username from one Android activity to next activity.These data can be passed via Bundle by intent.

The reuse of other application components in Android is known as task.

Example: From component of your application, you may need to access Phone Book app of you phone. From your application, you open the PhoneBook app, select one contact, and then return the selected data to your application again.

4. What are the types of intent?

There are two types of intents. These are:-

  • Implicit Intent

Calling using Intents:

Uri num = Uri.parse(“tel:”+phNum)
Intent i = new Intent(Intent.ACTION_CALL, num)
Sending sms Intents:

Uri num = Uri.parse(“sms:”+phNum)
Intent i = new Intent(Intent.ACTION_SENDTO, num)
i.putExtra(“sms_body”, “…..”)

Accessing Web Links

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(“”));

  • Explicit Intent


Every system needs continuous improvement. Feedback, positive or negative, plays an important role in that improvement. Humans are fairly instinctive in interpreting the tone of the feedback. But, to teach a machine to understand the same, is highly complex. Various algorithms and tools are available today to automatically identify and categorize opinions of any textual feedback.

The application of sentiment analysis is wide and useful. It gives us a wide overview of opinion regarding various topics. Sentiment analysis provides the ability to quickly understand the impact of any product or system and react accordingly.

In one of my works, I applied sentiment analysis to predict the opinion of students regarding various academic dimensions of an institute. It is published at Springer. I used R for the purpose and was playing around with various packages already existing at CRAN but none of them was working according to my need. So, I conceptualized a tool, which applies text mining techniques to elicit insights from textual data and  published it as an open source package (RSentiment) to CRAN.

Continue reading

RSelenium: A wonderful tool for web scraping.

For one of my projects, I needed to fetch data in R from online sources. We all know that its a common practice to collect data from Twitter, Facebook and other online social media websites and analyse them. I used to do the same using the XML package until a problem occurred while scraping data from this. Even after looking up the internet, I was unable to find a solution. Hence, I raised my concern at Stackoverflow where one was generous enough to tell me about the RSelenium package. And trust me, I fell in love with this package. Kudos to it’s author.

But I will have to admit, I faced lots of trouble while using this package even after following the steps mentioned here. The following steps are written in a simple but detailed manner to easily setup the RSelenium package.

Continue reading

Scientifically Beautiful Indian Traditions

For years, Indians have followed innumerable traditions and rituals , majorly religiously but there are beautiful scientific and logical reasons behind these rituals.These logical meanings are ignored as the rituals are passed from generation to generation, sometimes leading us to criticize them as superstitions.These traditions are still in practice by us in day -to-day households. Some of them are listed in this blog post.


  • Namaste – Indian way of greeting people

While greeting people, Indian join their palm together to wish “Namaste”. Pressing our palm together presses all the tips of our fingers which in turn creates pressure at ear, eyes and mind and helps us to remember that person.


  • Burning Agarbattis during ritual practices

Buring of Agarbattis or incense sticks are part of our Indian culture for years. Ever wondered why? The aura  of these burning sticks not only refreshes our mind and soul, but also cleanses the surrounding air by fighting against germs, bacteria etc.


  • Eating at floor

Many people used to sit in Sukashan position during lunch and dinner on the floor. This is one the important exercise in yoga where we sit cross legged. This position helps in digestion.


  • Blowing of Shankhas

    The shankha or conch is the shell of sea snail (scientific name Turbinella Pyrum) . In ancient India, the conch was inevitably blown during arati or worship of the deity. The sound of conch would fill the village then, and those who could not make to the temples or were debarred from entering the same could stop by hearing the sound and pray to the Almighty.

It is believed that person who blows the Shanka never develops any respiratory problem. Eminent scientist Acharya Jagadish Chandra Bose has proved that the sound of shankha replaces negativity of the surrounding with serenity.  Shankas are blown during sunrise and sunset so that strong rays of sun don’t obstruct the sound waves. These waves destroy the bacteria and cleanses the surrounding.


Continue reading

Android Dictionary

Learning a new language is hard because it requires new cognitive frameworks. While learning a new language, you will come across new terms and words whose meaning you need to learn along with it’s usage. With age and experience, your vocabulary will develop and that will serve as a fundamental tool in communication.

Developing Android apps is similar to leaning a new language all together. Although it primarily uses the Java language for coding, one also has to know the underlying Android framework, the structure on which it is based. Following is a list of some of the online available dictionaries which you may refer to whenever required during your learning or implementation process. The more you use it, you’ll reinforce your knowledge and your memory.


Introducing Views

Views are the rectangular shaped, basic building block of a layout or user interface that assures some content on the screen. Views – as the name suggests – is used to view any content on the screen. Without it, it is not possible to display anything on the screen. Thus it is the most essential element of any UI screen.

Views can me of various geometric shapes and sizes. These can be combined to form advanced views. All of these views and combinations form the layout of a screen. Here, I give an example of a view, complete with markings for easier understanding.

WhatsApp Image 2016-08-17 at 8.33.00 PM (1)

WordBin Login Page

This is a screenshot of one of our published apps, WordBin. Here I have marked the views in black. These views when grouped together, formed the Login page (layout). Any such combination forms different layouts.

Here, it is clearly visible that the bounds of the views can both me transparent (view marked “1”) due to it’s background, and can also be clearly distinguished (view marked “2”). Using the various properties of the views and using its features we can design any view as per our requirement.

Talking from a more programmatic point of view, View is an Android Base class from which all other types of views inherit.

Most Commonly Used Android Views:

  • TextView
  • EditText
  • Button
  • ImageView
  • ImageButton
  • CheckBox
  • RadioButton
  • RadioGroup
  • ListView
  • Spinner
  • AutoCompleteTextView

Since in Java, the norm is to follow Camel Case, the above classes follow such specifications. The above are just a few library classes of the vast Android library. Developers can define custom views and layouts as well on XML files. These custom views must be bound by some Android rules, but mostly they are flexible.

XML (Extensible Markup Language) files store the design of each user interface and  Java is required to implement it’s interactivity with other Java files. Android Studio is the most commonly used IDE to design the entire application.

The intention of this post was to give a basic idea of the View element of Android. Professional developers don’t memorize everything. Looking up information and implementing them properly is a key part of the job. But to implement properly, one should have their concepts clear. There are online sources which I found very useful while developing applications and which I used to refer to for implementing codes. But most of these concepts were not clearly stated in those sources. I learnt these over time after developing many applications. Hope this helps you.

Subscribe and keep checking for more posts soon.

Thank You.

Reading multiple files.

By now, we all are familiar with reading csv file into R. But, what if there is a block of operations that we need to perform on multiple files? I think that will be a quite tiring job to include each csv every time and run the script.

The best and the easiest way will be to automate the whole process for which we need to design a Rscript.

Step 1:  We begin by listing all the files in my working directory. We have specified the file format by mentioning “.csv ” as pattern.

file_list <- list.files(pattern="*.csv")

Step 2:  After listing, it’s time to find the number of csv files in the directory.

l <- length(file_list)

Step 3: Now, by running a loop, we can access the content of each csv file.

for (i in 1:l) {
  x <- read.csv(temp[i])

Yeah! by now we can read the contents of all the files automatically by running the  script.

Now, if you have the csv files with different number of columns and you want to work with specific columns of all the csv files, but the column number of that column is different in different csv file, it will be a quite difficult situation to handle.

Say, for an example, I have three files names “A.csv”, “B.csv” and “C.csv” and I want to work with “Entropy” Column of all the csv files, but it occurs as 3rd column in “A.csv”, 5th column in “B.csv” and and 9th column in “C.csv”. As there is no uniformity in the column number, it cannot be accessed dynamically as desired. This will be a great fallback in automating the process. So, what I would do is:

## checking if the name of the column is "Entropy"
if(collnames(x)[j]=="Entropy") {

  ## saving the original column name for future use

  ## changing the name of the jth column

  ## accessing the column by it's name
  ent [q]<-entropy(table(x$test))

  ## again assigning the original column name to the jth column

So, finally my RScript looks like this :

file_list <- list.files(pattern="*.csv")

for (i in 1:l) {
  x <- read.csv(temp[i])
  y <- names(x)

for( j in 1:ncol(x)) {

  if(collnames(x)[j]=="Entropy") {
     ent [q]<-entropy(table(x$test))

df <- data.frame(csv=character(), entropy=character() , stringsAsFactors=FALSE)
df <- cbind(csv,attribute)

Hope this helps and saves lots of time and effort. Happy Mining!

Output Text To Console

There are various ways to output text in RStudio.


Without New Line:




With New Line:

print("Happy Birthday")


Happy Birthday

If you want to add any more methods to the list, please leave a comment below.

Adding Multiple Comments in R

We all will accept the fact that we all have required at least once in our life to comment the previously written codes.

To comment a single line in RStudio, we can put “#” before each line.

But when we want to comment multiple lines at one go, we can use following in RStuido:-

  • In Windows: CTRL + SHIFT + C