mySQL connect and slowness experienced

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Hans-Helmut
Posts: 57
Joined: Sat Jan 14, 2017 6:44 pm

mySQL connect and slowness experienced

Post by Hans-Helmut » Sat Jan 14, 2017 7:35 pm

My name is Hans from Switzerland and I had a chance to play around with Livecode for some weeks now. I have a technical background and work with professional programmers. They have not been into Livecode yet.

I am personally using Windows 10, 64bit and Android. As I seem to understand, most users here are into Apple Macintosh and iPhone side?

Well, my intention is to use Livecode with experienced developers in a highly professional environment. I am not yet sure if this is possible. This is also my core competence, not as a core developer myself, but as a project manager for application development and with experience for over 20 years in this field.

---

I am now testing Livecode 8.1.2. Playing around I found that 2 x it completely crashed. And often enough on my Windows laptop, it stops for a while having the wheel spinning (Windows suspend mode) and it may take a while for the Livecode to recover.

And I was testing the direct database connection today using a MySQL database on a not too far away server provided for not much money from a service provider: Connection, downloading the names of all tables of a database instance, downloading then the details of tables, and then some small amount of test data. This works in general.

I noticed that even some seconds of inactivity close the database connection. Maybe it is an issue to solve on the server side?

But what I find is that Livecode IDE seems to be awfully slow. The speed is varying for connecting or receiving table definitions or receiving selected user entered data. But it was never below 2 seconds for about 10 rows and it may take 5 seconds or more to retrieve and indexed list of names. Especially retrieving table definitions is taking a lot of time. Since this is NOT the case using other programs, I am just wondering if this is "normal"?

Also, what I find (I once tested version 7 and 6) that the desktop application version 8.1.2 of LiveCode somehow is slower and feels "sticky". For example, opening the script editor with not a very big script, and then changing the window, selecting the message box and executing a command handler from there takes noticeable time until even the mouse can enter the message box field. Well, it all seems to be such a nice framework, but behaving so slowly that this could kill all interest for anything but local hobbyist work.

Maybe it is just me or my experience. But to be highly professional for enterprise development - I would not yet risk such step to recommend to customers. Nevertheless, I am monitoring and wishing to see that these versions become more stable and much more performant and responsive to user entries and actions.

I would be glad to go for the enterprise version and pay for that. But currently, I can not yet see the acceptance. Nevertheless, I am looking with a big hopeful eye.

Could someone possibly tell me that I am doing something wrong using direct MySQL connections and why it is "sooooo" slow and non-performant?

:oops:

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: mySQL connect and slowness experienced

Post by Dixie » Sun Jan 15, 2017 11:20 am

Use an .lc script on your server... I use mySQL a lot, making the connection to, and letting all the database queries happen, from the server the output is returned to your application... very rapid !

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: mySQL connect and slowness experienced

Post by AxWald » Sun Jan 15, 2017 12:15 pm

Hi Hans,

welcome!
Working professionally with LiveCode & databases myself, I may be able to give a helpful hint to some topics. I'm sure others will come to provide a broader view. So I'll concentrate on the points in your post that "raised an eyebrow" when reading ;-)
Hans-Helmut wrote:I am personally using Windows 10, 64bit and Android. As I seem to understand, most users here are into Apple Macintosh and iPhone side?
This is correct. Not only the by far most users are Apple addicted, RunRev (the company behind LiveCode) also has a strong emphasis on iProducts (the latter may be a cause for the first). As you can easily recognize by the style of their web presentation (or by reading the change notes of the few last years) they view LC as "the tool" to quickly churn out "apps" for iGadgets.
Android, Linux and Windows are supported, too, but to a much, much lower degree. And thus have a quite smaller user base.

Nevertheless LiveCode is a great developing environment, including cross platform distribution, even for tasks by far surpassing the creation of another mahjong clone, or the umpteenth video player for tiny screens.
It's possible to create things with it that actually earn money, else I wouldn't use it ;-)
Hans-Helmut wrote:I have a technical background and work with professional programmers. They have not been into Livecode yet.
Here I see a serious problem. LC (the language) is fundamentally different to traditional C-like, and even to the newer Basic-like languages. Sometimes I still do VBA coding (foe MS Access), and it doesn't go together well - it usually takes a day of frustrating accommodation to finally throw the switch in the brain and start to think in the new context.

Having a team of professional programmers learn & switch to LC? This may work, but may cause a lot of trouble, too.
Judging based of myself, who suffers eye cancer if forced to read only PHP and its wasteland of parentheses, this will fail miserably. But your developers may be better than this lonely guerilla coder :)
Hans-Helmut wrote:I am now testing Livecode 8.1.2. Playing around I found that 2 x it completely crashed. And often enough on my Windows laptop, it stops for a while having the wheel spinning (Windows suspend mode) and it may take a while for the Livecode to recover.
The 8.* versions are rather new and still in heavy development. There are some few grumpy old dev's among us that regard it not yet reliable and stable enough for serious work, and prefer the 6.* for their use.
6.* also is commonly regarded as much faster in many aspects, where the newer 8.* and 9.* versions are getting better and better.

You're not forced to use the new versions, read the release notes on the download page and judge yourself what's needed. For instance, if you don't need support for new Apple OSses and can live without the new widgets and HTML5, you can easily use 6.5 (fastest ever) or 6.7.10 (as I do).
Hans-Helmut wrote:I noticed that even some seconds of inactivity close the database connection. Maybe it is an issue to solve on the server side?
This sometimes comes with MySQL databases configured to serve web sites - they can be optimized to answer thousands of tiny queries in quick succession, avoiding resource-blocking long sessions.
I generally don't use "standing connections" at all with web dbs - too much hassle managing it. Instead I work with short connections, one at a time:

Code: Select all

   put revdb_connect("mysql","myServer.org",myDBName,myUser,myPass) \
      into MyDBID
   if MyDBID is not a number then  --  connecting failed
      db_Err someParams --  error handler here
      return empty
   end if
   put revdb_querylist(tab,return,MyDBID,StrSQL) into MyVar -- send query
   get revdb_disconnect(MyDBID)
   if item 1 of MyVar is "revdberr" then  --  something went wrong
      db_Err someParams--  another error handler here
      return empty      
   else
      return MyVar  --  return result of query
   end if
This is (the relevant part of) my basic shared handler for select queries. There's another one for action queries, quite the same, just "revdb_execute()" instead of "revdb_querylist()". And with these two handlers I do all of my database work.

You may feel tempted to use the long list of functions and commands LC provides for further database use, and maybe even the dreaded DataGrid, the alluring bane of any LC newbie. Think twice!

I avoid those like devil the holy water. I can nearly sing SQL (and take the view that who doesn't shouldn't be allowed to even touch a db ...), and I generally try to use the suiting tool for the job - so I set up my databases with HeidiSQL (or another good db manager) including structure, views, procedures etc.

Then I use the superior chunk handling capabilities of LC to construct carefully crafted SQL statements, and throw them to the db. Finally I use LC again with its easily manageable interface components to present the data, and to let the user interact with.
Hans-Helmut wrote:But what I find is that Livecode IDE seems to be awfully slow. The speed is varying for connecting or receiving table definitions or receiving selected user entered data. But it was never below 2 seconds for about 10 rows and it may take 5 seconds or more to retrieve and indexed list of names.
Since my interactions with the db only consist of sending commands and receiving results they are usually done in a low millisecond range, limited only by connection speed. And since all of my views and procedures live on the database server it's only a question of the available resources there (and the way how the db is set up and the views and procedures are written) how fast the db spits out its results.

Hope I could help a bit, must get back to work. While writing this a new idea crossed my brain ...
I'd like to emphasize that above is my personal opinion, of a quite old developer of highly specialized & customized database front-ends and process automation tools that wouldn't survive a week in a today's programmers team ;-)
So my opinions are strongly biased and should be taken with a grain of salt.

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

Hans-Helmut
Posts: 57
Joined: Sat Jan 14, 2017 6:44 pm

Re: mySQL connect and slowness experienced

Post by Hans-Helmut » Mon Jan 16, 2017 7:10 am

First of all, thank you for overwhelming replies, for considering a server-side implementation of Livecode from Dixie and the many details and additional thoughts AxWald has been going into.

You actually raised a big number of questions and thoughts which do not belong to this thread here. I might open another one if I can order my thoughts well enough.

Allow me to come back to the original question:

Scenario using local DB?

Would your answers not mean - since LC is not a web browser - to locally use something like SQLite and find the best possible way of synchronizing with a database management system out there? I also tested SQLite and locally there is no issue regarding performance. I would think that there should be a background process allowing such synchronization without affecting the user.

Is there any solution already where such synchronization of remote and local data storage has been tested and deployed? Could we learn from this?

Actually, this would be similar to how my email data is currently handled. A user defined period of data is kept locally on my phone and there is no issue in downloading and uploading all the time.

If possible, I would appreciate some comments on how to do this using LiveCode to not invent the wheel if not needed! )

Connection script

Thank you also for the script for connection and error handling. This is actually working on my side, I just can not bear the response times and the slowness receiving data seem to be handled through the current LC 8.1.2 version and even putting the application into suspense mode all the time.

Since my "direct" connection to MySQL drops all the time (have to see on the server side), I tried to have an automatic reconnect. So, I was successfully trying to fetch the error, then automatically connecting again, and if not successful after 3 attempts, I drop the connection with an error message.

Even if this is not the best way talking to a database out there, I really would love to get it working successfully and with the expected speed.

Which version of LC?

Of course, I am not a professional with LC and there are too many mistakes on my side, but from the tests so far following all instructions, this 8 version does not yet establish my trust. I did not test 9 waiting for a stable release. The latest 7 version "feels" more stable and predictable, but it is also not too performant compared to web applications running on the same server with the same MySQL database (not professionally used DB though).

Since working with Russian, Indian and Chinese developers and focussing on international markets, UTF8 text encoding is a requirement, and we do not want to go into the headaches again using various extended ASCII sets, we will probably not use any version 6 even if it has significant speed advantages.

By the way, I am using UTF8 on the MySQL side. When text decoding the result set then characters are not UTF8 any longer. When just inserting the result into any field without decode, there is no issue and all characters show correctly. I am just thinking about this since everywhere people write that communicating with anything outside, to text encode and decode is a requirement?

Testing going through middleware

I agree. I need to be setting up a connection to some middleware and then have the server talk to such middleware.

1. Testing MySQL (Maria... whatever) going through Livecode Server
2. Testing MySQL using PHP (or ...)

Since I can not yet (and also do not want yet) test LC server on a remote server machine, I would like to ask if there are standard scripts for Livecode (client side) and PHP scripts (server-side) talking to each other and managing result sets and issuing SQL statements. But as long as there are no stored procedures which can be called, SQL statements still have to be sent from LC client to the server.

The reason for being hesitant about server-side deployment is that in most companies, servers are highly protected and any kind of testing is nearly impossible except for those guys managing the server, while even they can not really do anything except setting up a test server or receiving special permission which is not what I intend to go through for the moment.

Supported protocols?

Therefore, I assume that my focus will still be on testing Livecode as a client talking to whatever is ALREADY available on the server side and using standard authentication processes including the latest standard OAuth2.

Which way to follow? Even though searching, I did not yet find a suitable cookbook for such client-server related Livecode scenario, just code snippets which I can not yet put into practice, but I may have missed something. There is simply too much to read and to search and I honestly feel that I can not see the wood for the trees at the moment.

If you or anybody feels that it is the wrong approach - I am more than willing to learn and correct. Any direction is highly welcome ).

HHH

sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: mySQL connect and slowness experienced

Post by sphere » Mon Jan 16, 2017 10:32 pm

Hi Hans,

well there is a section Database in this forum and it contains a little "How To" you can play with some middleware using PHP with PDO commands. An advantage of PDO is that you can use it with almost any Database by simply changing 1 or 2 lines in your script and not need to do any furhter adjustments to your PHP script for a certain database. PDO takes care of that.

See http://forums.livecode.com/viewtopic.php?f=12&t=27521 for this little How To

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: mySQL connect and slowness experienced

Post by MaxV » Wed Jan 18, 2017 6:18 pm

Dear Has,
did you try to connect to MySQL with the standard command line client?

Code: Select all

mysql -h http://where.is.my.db  -u myuser -p 
and then test the same queries with the mysql client?
Probably is the mysql server that is slow.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: mySQL connect and slowness experienced

Post by AxWald » Wed Jan 18, 2017 10:39 pm

Hi,
Hans-Helmut wrote:[...] I just can not bear the response times and the slowness receiving data seem to be handled through the current LC 8.1.2 version and even putting the application into suspense mode all the time.
This I couldn't get out of my head. So I had to test it myself.

But before, the suspense problem - quite easy, you need to keep your mobile app alive, else the OS will push it aside. For this I have a handler in my standalones (if I really need this - don't do this carelessly!):

Code: Select all

on upDateClock
   if the short name of the topstack = the short name of me then
      put the abbr system time into fld "clock_fld"
   end if
   send "upDateClock" to me in 10 seconds
end upDateClock
This not only shows the time, it also keeps my app alive w/o causing any troubles.

Now to the "slowness" problem. Since I'm working a lot with it, and basically all of my programs make heavy use of db connections of all flavors, I'm sure I'd have recognized such a problem if it existed - but I have not. One thing I cannot emphasize enough:

Long time database connections are not reliable over the internet. Never. In no program mankind ever invented. If you haven't had troubles yet using such, only the opportunity for maximum damage hasn't come yet and Murphy is still waiting, patiently.

OK, this said, let's go on. I grabbed some stuff from my virtual workbench, threw it together and polished it a bit:
  • I have a db query to test if there have been made orders yet for the jobs received. I modify it to give me 1 record at a time, for this test. This query runs with an average of slightly below 50ms on the db server itself.
  • I have set up a small stack with a repeat loop: connect, query 1 record, disconnect, test the result.
  • I test this with any LC version that I have in use here.
Result:

Code: Select all

8 hits; Livecode version: 6.5.0
200 ms/ query (19974 ms for all 100 queries)
-  47 ms for ping time;
-  50 ms for query time (avg.)
------------------------------
  103 ms computing time/ query average

8 hits; Livecode version: 6.7.10
199 ms/ query (19878 ms for all 100 queries)
-  47 ms for ping time;
-  50 ms for query time (avg.)
------------------------------
  102 ms computing time/ query average

8 hits; Livecode version: 8.1.2
199 ms/ query (19916 ms for all 100 queries)
-  47 ms for ping time;
-  50 ms for query time (avg.)
------------------------------
  102 ms computing time/ query average

8 hits; Livecode version: 9.0.0-dp-4
200 ms/ query (19997 ms for all 100 queries)
-  47 ms for ping time;
-  50 ms for query time (avg.)
------------------------------
  103 ms computing time/ query average
You see, I subtract the query time on the db as well as the basic ping time (that I test before) - these are numbers that are not in LCs responsibility. Remains a quite similar number for all 4 tested LC versions:
Slightly above 100 milliseconds for connecting, querying, counting up 1 or 2 (if hit) variables, and disconnecting. Not this much.

Above was from home, I just tried it at my working place:

Code: Select all

8 hits; Livecode version: 6.7.10
126 ms/ query (12629 ms for all 100 queries)
-  29 ms for ping time;
-  50 ms for query time (avg.)
------------------------------
  47 ms computing time/ query average
This machine (a venerable HP 6005 pro with an AMD Athlon II X2 B24) is a bit snappier, and the connection is better.

So I cannot see a problem. 47 ms! Either I fundamentally misunderstand the OP or something other is wrong. I have attached the test stack, beware that you'll have to add your db credentials, and you'll have to fill in a suitable query, maybe doing some adjustments - I have added a lot of comments, and where you see "*****" there's some work to do ;-)

For sure nobody in a right state of mind would solve a real task in this way - it's a setup to test how fast LC handles database connections & queries. In a dummy function "demo" there's the SQL how I'd get the not-yet-ordered jobs ...

Enough for today, I'm a bit busy these days. I'll post a bit more regarding SQLite, per chance I'm just in the middle of implementing a local cache db with it ;-)

Have fun!
awa_DB Test.zip
example stack for testing db connect speed
(2.39 KiB) Downloaded 264 times
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: mySQL connect and slowness experienced

Post by MaxV » Thu Jan 19, 2017 10:13 am

Hi all,
I suggest you to this link: https://www.db4free.net/
they give you a free MySQL server for testig.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Post Reply