Python modules for connecting to the database server

A subforum dedicated to topics around the NAS.
Post Reply
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Python modules for connecting to the database server

Post by hamishmb »

This morning I have been doing some research on Python modules for connecting to our database server.

Modules I have found so far:
Benchmark tool (might be useful to test our setup):

Instructions and tool are at https://github.com/methane/mysql-driver-benchmarks.

Unfortunately it seems being stuck on MySQL 5.1 might be a problem, but there is at least one module that seems to support it. I will look into building a newer database server for the NAS box when I get the cross compiler working. I will post updates here if I discover anything new.
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Python modules for connecting to the database server

Post by TerryJC »

Hamish,

There was a fairly useful article in this month's Linux Format about using Flask to develop Web Apps. It never got further than 'Hello World', but it led me to viewing a brief Tutorial on You Tube about developing a web page for accepting comments. You may remember that when I was first looking into developing the Webserver at WMT for the Audio Guide etc, I was exploring the idea of implementing a Content Management System to allow the WMT staff to upload new audio files and / or Quizzes. In the end it was put on the back burner, but at the time Ralph suggested using Flask.

Flask (http://flask.pocoo.org/docs/1.0/) is a micro-framework for developing Web Apps, so won't necessarily be any use for writing to the Results Database, but it is likely to be extremely useful for the Visitor / Staff GUI. Apparently, it is a fairly lean framework, but it is extensible and extensions exist for database access. AIUI, Django is also a powerful tool which can cope with database applications, the difference being that Django arrives fully fettled (and is therefore limited to what you get), whereas Flask is much more flexible.

Anyway, Flask is what we've always said that we should use for Web applications at WMT. It's not set in concrete; the Audio Guide and Kiddies Quiz were culled from examples that I found on the Internet and are very simple in comparison, but that doesn't mean that we shouldn't keep it in mind.
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Python modules for connecting to the database server

Post by hamishmb »

Flask sounds like it might be a good idea. Mostly I'm thinking from the perspective of connecting the river control system pi's to the NAS box with this, but this could definitely be useful.

A quick skim read of the documentation suggests that Flask uses standard python libraries to connect to the database, and then wraps them into the rest of its framework. This is good, because otherwise connecting to our obsolete database server would almost definitely be a problem!
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Python modules for connecting to the database server

Post by hamishmb »

So, I tried mysqlclient and did a stress test with our NAS box to see how it handles a flood of requests (though only one at a time). Here are the results from the script I made:

Code: Select all

hamish@hamish-Alienware-X51-R2 ~ $ python3 test_db.py 100000
Creating 100000 rows...
Avg of three tries: 57.98124099100005
Reading 100000 rows...
Avg of three tries: 3.957569676666632
Updating 100000 rows...
Avg of three tries: 72.07151066133322
Deleting 100000 rows...
Avg of three tries: 62.012823819000005
hamish@hamish-Alienware-X51-R2 ~ $ 
This is not blazingly fast, but should be perfectly good enough for us I think. The script is attached for anyone who;s interested.
Attachments
test_db.py
(1.68 KiB) Downloaded 96 times
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Python modules for connecting to the database server

Post by TerryJC »

Excellent!
Terry
Post Reply