Is the server script associated with an SSP app in...
# suitecommerce
t
Is the server script associated with an SSP app initialized on every request? If I set up a function to store something in a global variable, could a different user hitting the same SSP app access it or is each request and/or user isolated? I’m trying so understand the context.
p
Each time you hit a service or ssp file, the libraries get evaulated, then the actual ss/ssp gets evaluated. Tje execution is isolated on a session basis as a classic server side web language/framework (think PHP for example) . That being said, if your service or SSP file sets a caching flag on the response, then this becomes the same response for everybody hitting that url. The URL will be stored in a CDN and next time somebody hits that service, most likely it would be served from there and not from NetSuite.
If you want to store something for a user session, the best place to do so is nlapiGetContext().setSessionObject
if you want something globally available for all users, if it's dynamic and updated frequently, most likely it belongs on a custom record instance.
and if you want a global cache shared across all sessions, there's nlapiGetCache()
t
That makes sense. So the libraries are evaluated on every hit. I was pretty confident on the rest of the process but uncertain about the libraries “global context”. That tells me there could be an argument for keeping the libraries light and splitting functionality across multiple Apps if necessary. It’s not like a NodeJs app that cold starts once. It sounds like your saying each request is a cold start for the environment. Very interesting. I wonder why it’s built this way. It seems really resource intensive.
I’ve recently had to start grabbing promo codes before login and setting them in the same function after login because for whatever reason the session always breaks. It’s had me digging into context a little more.
p
I think there are multiple phases in the evaluation of libraries, some most likely are cached (the parsing of the JS files, for example) but the execution itself isn't (so every define() you see actually runs the define function every time and when you require it the inside gets evaluated, etc... ). So i'd say it's a "warm" (not hot) start. There's not much info on this and it might be wrong and it's mostly based on empirical evidence, some knowledge about NS... I think for the full SCA code, the evaluation of all the libraries code takes about 200ms of execution for example, on a warm run - which also includes for example reading configuration (which is a query to a record, but that also is heavily cached by NS)
SSP 2.0 is different and i think this might be optimized, but i hadn't got the time to play around with it much.
t
Makes sense. JavaScript is fast as long as the resources are available. I haven’t found much documented on it either. I run all requests to NetSuite through a load balancer and reverse proxy so I’ve hit a lot of fringe cases over the years. If we only had more time to play:-) thanks for the feedback
p
well, SSPs and all NS server JS runs in rhino (or it has historically been rhino and changed in the last release(s). ) So it’s not super fast but for our use cases i don’t think it’s particularly slow either.
You’d wish for 15ms response times but with such a large suite with so many capabilities, layers, and years, that is not too realistic