Webserver Development

This Forum is for discussion about the development of the software to control the playing of the music in the Minster Nave and the bells in the Tower.

There will be two programs; both based on the original software but now running on two Pis.
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Webserver Development

Post by TerryJC »

I've got the Webserver working, but not by using nginx and uwsgi. The point about uwsgi launching new instances of the App and then killing them when the page has been served is a double whammy for this development:
  • If two people simultaneously try to access the page at the same time, uwsgi will give each their own instance of the statusmonitor.py App. For us, this is a problem because the minstermusic program only has one socket defined, as has the statusmonitor App. This would result in a major issue with address conflicts (eg 'address already in use error') unless the sockets code was rewritten to keep supplying a new socket each time.
  • The above problem can (allegedly) be mitigated by using the uwsgi cheaper subsystem, which should allow the number of workers to be limited. However, I couldn't make that work and decided to cut my losses because of the next problem.
  • The statusmonitor App has no idea what the minstermusic program is doing let alone the minsterbells program, so it will exit when it considers that it has given enough time for the 'worker' to complete its tasks. This can be extended by changing the worker-reload-mercy parameter but that would probably have to be so long that it would prevent other elements of the App working properly.
We could of course rewrite all the code to not use sockets to exchange messages, but that would be a fair amount of work, The alternative would have to be something that doesn't rely on preventing multiple access, (such as a database), but that would require something special for the control side of things. Nearly all of the Flask examples I've found on the Internet rely on a database, but none of them are then controlling external programs, so that would take a bit of thinking about.

So what I have done is reverted to using the Flask Development Server as suggested by the guy on the Raspberry Pi Forums. It's not ideal, but it works and I don't think it's a security issue since the WMT Network is completely isolated from the Internet by the Firewalls in the WMT Webserver and the VPN Server.

Any comments on this?
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Webserver Development

Post by hamishmb »

Terry,

I have a solution in mind for this, but it would involve more development work on your GUI to split the web server and pages, and the rest of the application logic that talks to the other pi using the sockets.

There are a few different designs I can think of. Let me know if you're interested. As you say, though, using the Flask development server will be fine for our situation. I'll be implementing something like this for the mobile visitor GUI anyway, as that will run into the same issues.

The problem is that the application you wrote is kind of a hybrid Flask and general Python application, whereas what Nginx is expecting is some code that just renders a web page and then finishes rather than running in the background (this is the way that, eg, PHP would work).

Does that make sense?
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Webserver Development

Post by TerryJC »

Hamish,

A better solution would be welcome, but the system is packed up and ready to deliver to Penri.

Perhaps when you have sorted out your solution we could look into doing some kind of conversion. With regard to using PHP, were you thinking instead of Flask? Surely nginx would simply behave the same way?
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Webserver Development

Post by hamishmb »

Ah okay, let's do that at a more convenient time.

Yes Nginx would behave the same way, I was just drawing parallels to PHP in an attempt to explain why web servers do this, in case you are more familiar with how that works :)
Hamish
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Webserver Development

Post by hamishmb »

Just spotted this again randomly. Was any more work done on this?
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Webserver Development

Post by TerryJC »

Hamish,

No. It works and it's only us that use it.

There were other things to do so it was left. Plus. We didn't want to mess with it during the season.
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Webserver Development

Post by hamishmb »

Seems fair enough.

Is there still interest in fixing the issues you found? I can't remember exactly what I had in mind, but looking at this might be a useful precursor to properly starting work on the visitor GUI. Even if I can't resolve all the issues, it would get one roadblock out of the way for the visitor GUI.

Hamish
Hamish
TerryJC
Posts: 2616
Joined: 16/05/2017, 17:17

Re: Webserver Development

Post by TerryJC »

hamishmb wrote: 28/11/2021, 13:37Is there still interest in fixing the issues you found? I can't remember exactly what I had in mind, but looking at this might be a useful precursor to properly starting work on the visitor GUI. Even if I can't resolve all the issues, it would get one roadblock out of the way for the visitor GUI.
The only person who's used this to date is Penri and he hasn't used it that much because the WiFi issues made it unreliable. The WiFi has now been removed from the system and Cat 6 cable is being routed to the Minster to allow us to use Ethernet instead, so we perhaps should revisit this when that is up and running.
Terry
hamishmb
Posts: 1891
Joined: 16/05/2017, 16:41

Re: Webserver Development

Post by hamishmb »

Yeah, sounds good, I'll try to keep track of this then.
Hamish
Post Reply