Can I do lazy execution in ASP? Or: please offer any help to improve the performance of the old ASP site

I am trying to improve the performance of a website written in classic ASP.

It supports multiple languages, the problem is how it was implemented. It has the following method:

GetTranslation(id,language) 

What is called throughout the store:

 <%= GetTranslation([someid],[thelanguage]) %> 

This method simply looks up the identifier and language in SQL and returns the translation. Plain.

But incredibly inefficient. On each page load, there are about 300 independent SQL calls to receive an individual translation.

I have already significantly improved performance for many scenarios:

  • C # tool that scans .asp files and takes links to GetTranslation
  • Then the tool creates a “bulk cache” method, which (depending on the page) takes all the identifiers found and caches the results in the dictionary in one fell swoop.
  • Then, the GetTranslation method was updated to check the dictionary for any queries that it has, and go only to SQL if it does not exist (and cache its own result if necessary)

It is only so far.

When translation identifiers are stored in the database, I cannot select them (especially easily).

Ideally, the GetTranslation method on each call will create one large SQL string, which will be executed only at the end of the page request.

Is this possible in ASP? Can I get the result <% = ...%> as a reference to what is later allowed?

I also sincerely appreciate any other creative ways that I could improve the performance of this old, ugly beast.

+4
source share
5 answers

We use the i18n class with the namespace and language attribute in the oure e-commerce system. The class has a default function called "translate", which basically searches the dictionary. This dictionary is loaded using a memory template from a text file containing all translations for the namespace and language.

The skeletons for these translation files are generated by a special tool (actually written by vbscript) that analyzes ASP calls for i18n ($ somestring). File names are based on namespace and languages, for example. "Shoppingcart_step_1_FR.txt". The tool can actually update / expand existing translation files when we add new translatable strings to ASP code, which is very important for maintenance.

The performance overhead for using this method is minimal. Due to segmentation, our largest translation file contains about 200 translatable strings (including static image URLs). Downloading this query has very little impact on performance. I think it would be possible to cache translation dictionaries in the application object using some kind of third-party dictionary for reading, but IMHO this is not a problem.

Extra tip, use variable substitution on your line to improve translatability. For example, use:

  <%=replace(i18n("Buy $productname"), "$productname", product.name)%> 

instead

  <%=i18n("Buy")%> <%=product.name%> 

The first method is much more flexible for translators. Many languages ​​have different sentence structures.

0
source

I do not think you can do lazy execution in classic ASP. Regarding suggestions for improving productivity. You might have a class like this:

 Class TranslationManager Private Sub Class_Initialize End Sub Private Sub Class_Terminate End Sub Private Function ExistsInCache(id, language) ExistsInCache = _ Not IsEmpty(Application("Translation-" & id & "-" & language)) End Function Private Function GetFromCache(id, language) GetFromCache = Application("Translation-" & id & "-" & language) End Function Private Function GetFromDB(id, language) //'GET THE RESULT FROM DB Application("Translation-" & id & "-" & language) = resultFromDB GetFromDB = resultFromDB End Function Public Default Function GetTranslation(id, language) If ExistsInCache(id, language) Then GetTranslation = GetFromCache(id, language) Else GetTranslation = GetFromDB(id, language) End If End Function End Class 

And use it in your code

 Set tm = New TranslationManager translatedValue = tm([someid], [thelanguage]) Set tm = Nothing 

This will certainly reduce the number of calls in the database. But you have to be very careful about how much data you put in the application object. You do not want to run out of memory. It is also best to keep track of how long translations are stored in memory and whether they expire (removed from the Application object) when they have not been available for some time.

+2
source

<%= x %> just translates to Response.Write (x). There is no way to delay this.

In fact, classic ASP cannot do anything delayed, as far as I remember.

You have already done a lot in terms of writing a caching tool. The next step is to write a tool to convert these ASP pages to ASP.NET.

0
source

Your cache is the best savings you can make here, you can end the complication of pre-cacher.net, and just every call to GetTranslate checks your dictionary to enter it, if not, it can get it and cache it in Application space. It will quickly light up. Then there is the problem of updating the cache every day, but it will be done for you every 24 hours when the workflow is updated.

If you need it to be more relevant than this, you could pull out all your links like you using your .net cacher. Then you can create a new function to get all the records for a given set of identifiers, write a call to this function at the top of your ASP pages for each page, which will call your database with a single SQL line, with which you can copy the results to a local dictionary. Then modify GetTranslation to use the values ​​from this dictionary. It will need to be updated, but it may be part of your build process or just work done every hour / night.

0
source

The approach that I use in my own CMS is to load all the static language strings from the database into the Application object at startup using unique keys based on the variable name, language identifier, and CMS instance. Then I use page level caching in the array as the page is created, so the reusable variable gets cached and avoids a lot of trips to the application object, where possible. I use an array instead of a dictionary as the way my CMS function creates each page in sections where each section is isolated from each other, so I would create several dictionaries on the page, which is undesirable.

Obviously, the viability of this solution depends entirely on the number of variables that you have, and the number of translations that you have, and the number of variables that you need to get on each page.

0
source

All Articles