SHARED HOSTING FOR DATA SCIENCE APPS PROS & CONS

Santiago Berniz
5 min readJan 22, 2022

--

INTRODUCTION

Having previously deployed web apps on Heroku using data science models, I wanted to deploy a fun tweets sentiment analysis FLASK web app. Having a free Heroku account though, meant that my app will go to sleep if not used for a long period of time. However, I do have access to a shared web hosting account capable of running python scripts and DJANGO, which I am already using for other projects. That said, they use the FastCGI approach to connect the webserver to the FLASK app. This is something I never used, hence it was a learning curve. It was also a good experiment to help improve my skills.

BENEFITS

I use share hosting for almost everything because it provides me with many benefits. Cloud shared hosting services are an inexpensive alternative to AWS, VPS, or Dedicated Servers. An advantage of cloud shared hosting as it is, as the name suggests, is that they are cloud-based hosting and, therefore, decentralized. This provides the benefits of very fast loading speeds worldwide and not just on locations close to the server. While for static and some dynamic websites this is not an issue, if you are planning to do streaming, then decentralized is a better option. Additionally, they provide a lot of tools for website building along with One-click install scripts for WordPress, OSCommerce, Blogs, forums, etc.

Furthermore, some cloud shared hosting services offer Unlimited Disk Space, Bandwidth, Email Accounts, and more. All these benefits come at a low cost (less than $30 a year in some cases).

LIMITATIONS

As with anything, there are also limitations that come with shared hosting. These limitations are RAM and CPU access (around only 5%). This means that my scripts need to be very efficient and not take too much RAM during runtime or they can crash.

While these limitations may seem negative, they can also be very positive. By taking these limitations into account, I will be forced to write efficient code. By doing this often, it will become part of my coding style to always take into account code efficiency from the start. While I do usually take efficiency into account, I first focus on making it work and worry about efficiency later. However, these limitations mean I need to take code efficiency into account from the beginning for it to run. By writing CPU and memory-efficient code I can make sure it can run on limited resources as well as perform very well on computers with more power.

These limitations became apparent to me during my port of the salty tweets app to the shared hosting platform. From the beginning, when I was creating the web app, I already knew that it would be very CPU and RAM intensive due to the live data acquisition during the execution time. I knew that I might not be able to deploy it to Heroku, but it also surprised me to find that I was having trouble deploying it to my shared hosting.

For starters, I found that if I wanted my script to work with the hosting plan I already had, I had to forgo using unicorn or uvicorn background services because to do so would mean that I would have to add to the plan, increasing the cost. Therefore, to keep my current plan, I had to settle with an FCGI script and, while it can be a bit harder to set up for those not used to setting up FCGI scripts, once it is set up correctly, it works perfectly.

CHANGES NEEDED

Originally, I’ve set up my web app as a simple modular FLASK app, a main.py script, and a functions.py script. The finished FLASK app was set up as a package as well. While this works perfectly on my local system, as soon as I tried deploying it, I was having issues with both Heroku and my shared hosting. On Heroku, it was a simple error with the code, which I was able to fix rather quickly. For my shared hosting version, however, many changes were needed.

First, I had to create a .fcgi script. Since I had never done something like that before, it was definitely a learning experience. While it might not be used as much anymore, it is always good to have a broad knowledge of all the different technologies available.

At first, I thought that would be all I had to do. I was wrong. Although it was supposed to have worked, there were issues with access permission to other modular files. I contacted support about this issue but they were unable to help. Therefore, another change I had to do was to combine the entire code in one python file and the .fcgi file.

After making these changes, I was still having intermittent issues loading the app. I found that rearranging the code and putting all the functions and model loading at the beginning and outside of the @app.route worked like a charm and I had my app deployed to both Heroku and my shared hosting.

LESSONS LEARNED

While this project was only a personal project as a way to prove to myself that you can indeed create data science apps on limited hardware and software, I also learned a few lessons.

One lesson is that while there is usually a standard on how to do some things, everyone should be open to thinking outside of the box and not always follow the status quo. In this case, I learned how to execute FLASK apps with either unicorn or the FLASK internal server for development and that is the standard according to my professors. However, in this case, this was not an option to deploy to a shared hosting service and there was a learning curve for the FCGI method.

In addition, while FCGI might be an older method that is rarely used because it is slower, using it on shared hosting I had to make my code more efficient. This is a good experience, especially now that new hardware is faster and many programmers do not care as much for code efficiency as long as it does the job because the hardware can handle it.

Finally, I learned that it is definitely possible to create data science apps on limited hardware shared hosting.

LINKS

If you are interested in giving this a try and maybe modifying or making the code even better below are some Links

GITHUB: SALTY TWEETS WITH FCGI

SHARED HOSTING I USED: LCS IT AND MEDIA SERVICES HOSTING

FCGI Deployment: http://saltytweets.lcsitmedia.com/

Heroku Deployment: https://tweetsalty.herokuapp.com/

--

--

No responses yet