2

I am experiencing (very) slow page load times that increase proportionately to the number of active users on the system. I have a hunch that this is related to a custom defined thread object:

define stageStoreCache => thread {
    parent map
    public oncreate() => ..oncreate()
}

This stageStoreCache object simply mimics the behavior of a map whose data available across the entire instance.

Many threads are reading it and very few threads are writing to it. Is this a poorly conceived solution to having a large map of data available across the instance? It's a fairly large map of maps that when exported to map->asstring can exceed 5MB. The objective is to prevent translating data stored as JSON in the database to Lasso types on the fly.

It seems that the large size of the stageStoreCache is not what causes problems. It seems to really be the number of concurrent users on the system.

Thanks for any insight you can offer.

1
  • This implementation turned out to not be the issue at all. Instead, it was another thread object that was getting hit much more frequently. I reimplemented the thread object in a database table and that seems to have solved the issue with concurrent access. I really expected that keeping a thread object inside Lasso would be much faster and more efficient than having to round-trip through the database, but not so!
    – ATP_JD
    Jul 10, 2015 at 3:24

2 Answers 2

1

You said that this holds a map of maps and is rather large. If those sub-maps are large, it is possible that the way you are accessing the data is causing the issue. Here's what I mean, if you are doing something like this:

// Potential problem as it copies the sub-map each time
stageStoreCache->find('sub-map')->find('data')
stageStoreCache->find('sub-map')->find('other')

The problem comes in that each time stageStoreCache->find('sub-map') is called it actually has to copy all the map data it finds for "sub-map" out of the thread object and into the thread requesting that data. If those sub-maps are large, this takes time. A better approach would be to do this once and stash it in a local variable:

// Better Approach
local(cache) = stageStoreCache->find('sub-map')
#cache->find('data')
#cache->find('other')

This at least only has to copy the "sub-map" over once. Another approach that might be better (only testing could tell) would be to refactor your code so that each call to stageStoreCache drills down to the data you actually want, and have just that small amount of data copied over.

// Might even be better as it just copies the values you want
stageStoreCache->drill('sub-map', 'data')
stageStoreCache->drill('sub-map', 'other')

Ultimately, I would love for Lasso to improve thread objects so that they never blocked for reads. (I had thought this had been submitted as a feature request, but I'm not finding it on Rhinotrac.) Until that happens, if none of my suggestions help then you may need to investigate using something else to cache this data in such as memcached.

1
  • Yeah; think that was one of my feature requests — was hoping it would make it in 9.3 but don't believe it has.
    – Ke.
    Jan 14, 2015 at 11:37
1

Testing is the only way to tell for sure. But I would go a long way to avoid having a thread object that contains some 5 MB of data.

Take this snippet from the Lasso guide into consideration: "all parameter values given to a thread object method are copied, as well as any return value of a thread object method" http://www.lassoguide.com/language/threading.html Meaning that one of the key features that makes Lasso 9 so fast, the extensive use of reference data, is lost.

Each time you have a call for stageStoreCache all the data it contains will first be copied into the thread that asks for it. That is an awful lot of copying.

I have found that having settings and site wide data contained in smallest possible chunks is convenient and fast. And also, to only actually set it up when it is called for. Unlike the old approach that had a config file that was included on every call, setting up a bunch of variables where the majority maybe never got used on that particular call. Here's a Ke trick that I'm using instead. Consider this:

define mysetting1 => var(__mysetting1) || $__mysetting1 := 'Setting 1 value'
define mysetting2 => var(__mysetting2) || $__mysetting2 := 'Setting 2 value'
define mysetting3 => var(__mysetting3) || $__mysetting3 := 'Setting 3 value'

Have this is a file that is read at startup, either in a LassoApp that's initiated or a file in the startup folder.

These settings can then be called like this:

code blabla
mysetting2
more code blabla
mysetting1
mysetting2

With the beauty that, in this case, there is no wasted processing to initiate mysetting3, since it's not called for. And that mysetting2 is called for several times but is still only initiated once.

This technique can be used for simple things like the above, but also to initiate complex types or methods. Like session management, calling post or get params etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.