Django Cache solution for max_user_connections - database

My website has stated to get the following error: OperationalError: (1203, "User xxxxx already has more than 'max_user_connections' active connections")
From what I understand this is because there are too many requests to the database at one time and the database cannot cope. Ideally I need to setup caching for the database access and know this is pretty easy to do with Django, but the question is, which cache solution is best.
My hosting is on the MediaTemple gridserver platform if that helps. As far as I am aware I can use any or the solutions that Django provides: http://www.djangobook.com/en/beta/chapter14/
Is there a good way to figure out what the best option should be? I don't generally have much traffic, but sometimes there can be a spike and the content is pretty much static, except for the odd blog post, that doesn't have to be to 'fresh'.

Read a cache solution comparison here.I guess django-staticgenerator would be what are looking for.
And you can take a look at Johny-cache

Related

Is there a simple way to host a program with a small data file (esp. on Heroku)?

If you go to my Heroku-hosted to do list program, you can put test data in, but it's gone pretty soon. This is because, I learned, Heroku has an "ephemeral" filesystem and disposes of any data that users write to it via post. I don't know how to set up a PostgreSQL database or any other kind of database (although maybe I soon will, as I'm working through Hartl's Rails tutorial). I'm just using a humble YAML file. It works fine in my local environment.
Any suggestions for beginners to work around this problem, short of just learning how to host a database? Is there another free service I might use that would work without further setup? Any advice greatly welcome.
I fully understand that I can't do what I'm trying to do with Heroku (see e.g. questions like this one). I just want to understand my options better.
UPDATE: Looks like this and this might have some ideas about using Dropbox to host (read/write) flat files.
The answer is no. But I'll take a minute to explain why.
I realize that you aren't yet familiar with building web applications, databases, and all that stuff. And that's OK! This is an excellent question.
What you need to know, however, is that doing what you're asking is a really bad idea when you're trying to build scalable websites. And Heroku is a platform company that SPECIFICALLY tries to help developers building scalable websites. That's really what the platform excels at.
While Heroku is really easy to learn and use, it isn't targeted at beginners. It's meant for experienced developers. This is really clear if you take a look at what Heroku's principles are, and what policies they enforce on their platform.
Heroku goes out of their way to make building scalable websites really easy, and makes it VERY difficult to do things that would make building scalable websites harder.
So, let's talk for a second about why Heroku has an ephemeral file system in the first place!
This design decision forces you (the developer of the application) to store files that your application needs in a safer, faster, dedicated file storage service (like Amazon S3). This practice results in a lot of scalability benefits:
If your webservers don't need to write to disk, they can be deployed many many times without worrying about storage constraints.
No disks need to be shared across webservers. Sharing disks typically causes IO contention and can adversely affect performance.
It makes it easy to scale your web application horizontally across commodity servers, since disk resources aren't required.
So, the reason why you cannot store flat files on Heroku is because doing this causes scalability and performance problems, and would make it nearly impossible for Heroku to help you scale your application easily (which is their main goal).
That is why it is recommended to use a file storage service to store files (like Amazon S3), or a database for storing data (like Postgres).
What I'd recommend doing (personally) is using Heroku Postgres. You mentioned you're using rails, and rails has excellent Postgres support built in. It has what's called an ORM that let's you talk to the database using some very simple Ruby objects, and removes almost all the prerequisite database background to get things going. It's really fun / easy once you give it a try!
Finally: Heroku Postgres also has a great free plan, which means you can store the data for your todo app in it for no cost at all.
Hope this helps!

MEAN.JS, high latence / ways to find bottlenecks in web-development

:)
I recently came across MEAN.JS. I'm still a beginner in webdevelopment but all worked really fine so far. Up to one thing.
Unfortunately, all requests seem to take a huge amount of time - 300 - 4000(!) ms for a single call (have a look at the screenshot). I'm developing locally on a state of the art computer and wonder where the bottleneck might be. Does anyone have the same issues? Could you give me a hint how to attack this problem?
I've had a look at this and similar posts, but couldn't find a way to tackle it.
What are the ways to find bottlenecks in a web application?
The framework uses MongoDB, ExpressJS, AngularJS, Node.js. Could you give me a hint how to track down the source of those latencies in a Javascript-based application? (Maybe a tool, plugin or best practice approach in development?) Have you experienced similar issues?
Greetings,
Tea
It's hard to guess what's wrong as that latency can be originated from many sources, however if we put aside computer and network problems/configurations, and taking into account that you don't have any other processes running that can affect your app performance, the first thing I would check is the express configuration, i.e, the order in which the middleware is loaded. A misplaced middleware can indeed influence the app's performance.

Wordpress site has 6000 posts, causing it to be slow

These posts are being treated as listings for a directory, but they are not loading all at the same time.
I think it may be a database issue, I noticed my wp_postmeta size is over 20Mb
I ruled out all js and css issues already.
Thanks!
You might consider using the Query Monitor plugin to help you track the slow database queries…
Maybe a plug-in is causing your site to slow down. You could check this just to be sure... You can always check your database or something like that but sometimes it could be much smaller than you'd think. Also,
Use a plug-in like wp super cache to generate html files which makes your site slightly faster. Caching is always good in my opinion.
That said, run a db check.

What happens when a live site has too many users?

I'm new to production level web development, so sorry if this is obvious. My site has a potential to have a sudden surge of (permanent) users and I'm wondering what happens if too many users sign up in a short period of time, causing the site to run slowly. Since development takes time, would it just be a case of adding more boxes to the server, or does the site have to be taken down for code improvement?
Thanks
Don't worry even very popular sites go through this. Coding well is always a plus, but sometimes even that is not enough. Twitter being an ideal example, they started their messaging on Ruby but had to move to Scala as they became more and more popular.
Since you say you are new, can I suggest getting yourself familiar with caching queries and caching static content? Learning about good indexing practices on SQL server should also be helpful in dealing with a large influx of users.
Both but code improvement would be the first to target. Writing code that will scale will help you out the most. You can throw more servers at it behind the scenes but you would have to do this less with well architected code that was designed for scalability.
Depends on the technologies your using and how the code you write is written.
Since you tagged sql-server, when it comes to databases in general, you are limited by your locking strategies and your replication architecture a lot of the time. How you design your database and put it into production has big impact. Things that have to happen in any type of serial manner are bottlenecks. Check your execution plans, watch and manage your indexes, and replicate and distribute your systems if you can.
The best way to understand your scalability limitations is through load testing and proper QA.
If you don't do it right, your users are sure to be unhappy when you start 503ing or timing out. :-)
If the site is developed in such a fashion that you can have multiple servers/data access layers, then scalibilty should not be an issue.
Create the app so that you can loadshed as required, and keep the code as flexible as possible.
But from past experiance. Performance tune once it is required. Write easily understandable and maintainable code, and fix performance issues as the occur.
The best advice I can give is to test your app and server before you go live, then you can see when you are likely to get problems and how bad they could be.
It is one thing to say 'it will go slow' but once you get past a certain point your app may crash or randomly give users error 500 pages.
Test with automatic scripts tools to stress the site and simulate sign-ups and random users visiting random pages.
If you have SSL make sure your tools simulate lots of different SSL connections rather than just different HTTP requests ( SSL handshakes take extra resources )

Where we can find database designs schemes (ERD or other) for very common use cases?

The question is more simple than what it looks. There are many use cases that are well known and people have put a lot of thought into them. For example: Audit trailing, login users, and so on. We are looking for a good resource site that present the DB design for those common use cases.
Check out
http://databaseanswers.org/
There are over 500 data models available for free there. It's not hard to convert them into a working database. For some of them, if you contact the webmaster, they will send you a working MS Access application with a built in database.
Even if you don't use Access this could serve as a prototype.
Try The Data Model Resource Book by Len Silverston. It has 3 volumes and not only shows but also explains the usual use cases.

Resources