Serving high volume custom scripts

We currently have a script that is served through a web server (Flask via Apache WSGI).

This is a user-configurable Javascript file that includes some general logic and some user-configurable options that differ from user to user.

The current method for serving it seems very inefficient to me, and to keep the configuration of each user in a local database and add to the common logic before submitting. For example:

var user_config = {...};
// ====== separation ======
var logic = (function() {
    // Consume config data here
});

      

Configuration is done when users sign up to our site and set up a range of functionality they want, but the configuration is basically very large JSON.

The reason this was originally done was to keep the client code as simple as possible. They just added a script tag to their site with their id:

<script src="http://path.to.script?id=ABC></script>

      

The problem I am currently finding is that I am trying to modify the originally developed method to better handle the high load as it seems to be struggling right now.

How can these individual scenarios be served for each user to minimize the load on our servers, and perhaps take advantage of some caching or other load-shedding features.

+3


source to share


1 answer


It depends on what is configured and how. If possible, ask the user serialize / json to encode their config parameters in the script request parameters.

Edit

Now that I have a little more information about the situation, I think you are not far from the optimal setting.

Since the configuration is quite large when serializing / converting to JSON, then I guess yes - you'll have to keep this on the DB. Perhaps there is a table / DB for this. UserId field + JSON configuration.

The best way for IMO to reduce the high server load would be to implement a RAM based caching layer like memcached.



Obvi make sure your db is also optimized, index the ID field if not already indexed.

Then put it all on some kind of varnish.

If your high load is caused by a huge number of different requests that can occur at any given time, I think you need to do some work to keep the cache constant for all active users.

If your scripts require a DB formatted entry to write metrics, perhaps consider porting that functionality to the client-side script and have it make an AJAX call.

Hope it helps.

+1


source







All Articles