I have an Embedded system, i.e. basically an ATMEGA based microcontroller with GSM Module. The GSM module exploits GPRS connection of the SIM to send GET request to a Webpage on my server. In simpler words, it is same as a person opening that webpage from his mobile device. When that webpage is opened, nothing special happens, I just extract the GET parameters and update the database. Now the problem comes. The database is online on a GoDaddy Server and when I send that update request from GSM device, it hangs for 4-5 seconds. Is there any other way by which I can update database and save my time ?
Moreover, I would like to know, for online database, what takes more time,
* Initiating a database connection, or
* using an UPDATE query to update the table ?
There are a lot of things going on here and you may have issues in many places. A bit too little info to solve the issue but here are some possible places to look.
Obviously, you have the issue of network latency and general response time from your web/database server(s) on GoDaddy. My first question would be how does a response from the MC compare to a get call via a web pages.
To specifically answer your question - initiating a database connection is usually the most costly part of the transaction. I am not sure what you are using on the database side so I cannot point you to specific resources. I am guessing MySQL? If so take a peek at https://dba.stackexchange.com/questions/16969/how-costly-is-opening-and-closing-of-a-db-connection for suggestions. On my own database I tend to tune them for performance. On GoDaddy you may be quite limited in what you can do.
However, I am going to qualify what I said above a little bit. Generally an update to a database should not be that slow. We could be dealing with poor database design or very large tables that have to have indexes updates as well. Again something to think about in your particular case. The other item to note is that you may be doing updates as shown below:
update myTable set myField = 1 where somesensor = 'a'; update myTable set myField = 1 where somesensor = 'b'; update myTable set myField = 1 where somesensor = 'c'; .....
and depending on the number of updates you are doing, how you are making the connection, etc. and the rest of your particular situation..... If you are using MySQL take a look at this example How to bulk update mysql data with one query? for possible ideas. Benchmark this!
I would suggest doing an explain plan to see what is happening to see if you can id where the problem is (check your version of MySQL). See http://dev.mysql.com/doc/refman/5.7/en/explain.html for syntax, etc.
There really is not enough info to say exactly but maybe this will give you some ideas. Good luck!