In this post I would like to highlight a neat way to set a useful bit of SAS Viya Programming Run-time Environment configuration from the command-line, and in the process remind you that pre-started (and reusable) compute servers are a good thing for SAS administrators to know about.
SAS Viya's Programming Run-time Environment has the ability to pre-start a pool of available compute servers. The idea is that when users request a compute session in a specific compute context in e.g. SAS Model Studio or SAS Studio, the compute session starts in a few seconds rather than a few tens of seconds because the compute session runs in a compute server that is already started. The user doesn't need to wait for the SAS Compute Service to ask SAS Launcher Service to launch a new Compute Server pod, wait for the pod to start up, and wait for all the containers in it to initialize. Those things still have to happen, but they happen before the user requests their compute session.
The apparent improvement in session start time is especially noticeable when you run something like a model pipeline which starts several compute sessions in quick succession.
The necessary steps to create a compute context which pre-starts compute servers are documented in:
However, if you like to script things so that e.g. your environment creation can be automated, read on. We're going to look at a way to enable a pool of pre-started compute servers with just three commands. Plus, the method we'll use can easily be modified to create other compute contexts with attributes and restricted access.
We have covered pre-started compute servers before. 18 months ago my GEL colleague Rob Collum wrote here about improving concurrency performance in SAS Viya. One of the things he covered was how to create a pool of reusable compute servers, and he showed how to do it using the SAS Environment Manager's web interface. And 14 months ago I used the settings we'll review today as examples in my post Add, update and remove compute context attributes with new pyviyatools. But it is a while since we've written about pre-started compute servers here, so perhaps they are worth mentioning again.
First, let's refresh our memories with a few reminders about pre-started compute contexts:
But with all that taken into consideration, if your users need to run a model pipeline - i.e. a series of model steps - in SAS Model Manager, or start SAS programs in Studio, and much quicker session startup time is worth the tradeoff of running the compute session as a shared account, then creating a pool of pre-started available compute servers might be for you!
Here's how.
You must store a credential for a shared service account whether your identities are provided by LDAP or SCIM. However, I have only had a chance to try it with LDAP so far, so the steps below are specific to shared service accounts provided by LDAP. Consult Stuart's post for how to do the equivalent when your identities are provided by SCIM.
If you are using password authentication, and your users are provided by an LDAP provider such as Microsoft Active Directory (AD) or Azure Active Directory Services (AADS), read on.
First, authenticate to the sas-viya CLI as an administrator using e.g. sas-viya auth logon, or the pyviyatool loginviauthinfo.py (described in loginviauthinfo.md).
Then optionally, run this to list existing compute credentials:
sas-viya compute credentials list
If you have not created any compute credentials yet, the response will be:
There are no shared service account credentials.
Then run this to save a compute credential for a service account called modelservice
, who has password mySecretPassword123
. Obviously, substitute the username and password of the service account your pre-started compute servers should actually run as for these example values:
sas-viya compute credentials create -u modelservice -p mySecretPassword123 -d "Shared service account called modelservice"
The expected response is something like:
2023/06/07 12:34:56 The shared service account credential for modelservice was created successfully.
If you like, confirm it was created by listing compute credentials again:
sas-viya compute credentials list
If the credential was created successfully, the response will be something like:
Shared Service Account Credentials: 1. modelservice - compute-password - Shared service account called modelservice
The file below is based on the example in SAS Viya Platform Administration > Servers and Services > Programming Run-Time Environment > Program.... Save it somewhere which I will refer to as /path/to/file/prestarted_reusable_modelservice_cc.json
.
{ "name": "Data Mining compute context as modelservice", "description": "A compute context for the SAS Visual Data Mining and Machine Learning application as modelservice.", "attributes": { "runServerAs": "modelservice", "reuseServerProcesses": "true", "serverMinAvailable": "1" }, "launchContext": { "contextName": "Data Mining launcher context" }, "launchType": "service", "authorizedGroups": [ "Modellers" ] }
Adapt the JSON compute context template to your needs:
/path/to/file/prestarted_reusable_modelservice_cc.json
to whatever file path and file name you wish to contain your JSON compute context definitionname
and description
for this new compute contextmodelservice
in the runServerAs
attribute"serverInactiveTimeout": "900"
. From the documentation reference in the next bullet: "Is used only when the reuseServerProcesses
attribute is set. The value is the time in seconds that an inactive server remains running before being terminated. An inactive server is defined as a server without an active compute session.". When idle, you will see the pre-started compute servers terminate at the end of such an inactive period - and new ones are restarted if this brings the total of compute servers in the context below the number specified by serverMinAvailable
.serverMinAvailable
attribute to the initial number of compute servers you wish to have pre-started. See note below.contextName
attribute:
"Data Mining launcher context"
"SAS Studio launcher context"
authorizedGroups
section from Modellers
to the groupID of the group you want to have access to this compute context, orauthorizedGroups
section - and the comma at the end of "launchType": "service"
- to make this compute context available to all authenticated users.
Note: Remember that pre-started compute servers will consume some resources on your Kubernetes cluster's compute nodes, and as explained above will also reserve resources for potential use, so that they cannot be used for running other pods. The optimal serverMinAvailable
number for the workload your users are running is something you may need to find by trial-and-error. I have seen a use case of a small environment with a couple of users who ran relatively small model pipelines, where 4 was a good value for serverMinAvailable
. I have also seen another use case of a large shared classroom server used for teaching classes of students how to design models in SAS Model Studio, where 25 was was the chosen value for serverMinAvailable
. This was the use case Rob used for the example values in his post. It is a value that you should tune, over time and with experience of what works best for your organization's workload.
Save your changes to /path/to/file/prestarted_reusable_modelservice_cc.json
.
To create the new compute context, use the sas-viya command-line interface, still authenticated as an administrator, to run this command:
sas-viya compute contexts create -r -d @/path/to/file/prestarted_reusable_modelservice_cc.json
Note: the @
symbol in front of the file path is correct and required. You can of course create - and update, and delete - a new compute context interactively in SAS Environment Manager. My aim in this post is to show how to do it from the command line.
If you have access to a visual interface which shows pods running in your SAS Viya namespace in your cluster, you should see the number of sas-compute pods increase. However, depending on the interface, it may be difficult to distinguish the sas-compute pods started under this compute context (and running as the modelservice
account) from other compute pods.
If you have access to the kubectl command-line interface for Kubernetes and a kube config file that lets you access your SAS Viya deployment's cluster, this command can show sas-compute pods launched specifically by the SAS Compute service (as opposed to by a user in SAS Model Studio or SAS Studio), and running as the modelservice
account:
kubectl get pod -l launcher.sas.com/requested-by-client=sas.compute,launcher.sas.com/username=modelservice
Tip: Scroll the textbox above to the right if necessary, to see how the username who requested the pod is specified as a filter to kubectl get pods.
Here are some example results, when my new compute context's serverMinAvailable
value was set to "1"
, and I had no other SAS Compute sessions running in this compute context or as modelservice
:
NAME READY STATUS RESTARTS AGE sas-compute-server-b91b1b9f-8827-4b57-9535-160cbf6e2cc4-t8mgl 1/1 Running 0 25s
Possible reasons you might not see the new compute servers starting up include:
Assuming you did see the new sas-compute server pods starting up, you can now see if they improve performance of your model pipelines.
Sign in to SAS Model Studio. If you limited access to the new compute context to only members of a specific group, sign in to SAS Model Studio as a user who is in that group.
Then, create or open a model pipeline. To change the compute context used to run each step of this model pipeline, click the 'Settings' icon, in the top right corner of the project tab.
In the Project Settings dialog, choose Compute Context, and switch from the default 'Data Mining compute context' to your new compute context which pre-starts compute servers:
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
I do not believe it is possible to configure individual steps in a model pipeline run under different compute contexts. The whole pipeline runs under the same compute context.
In the screenshot above, you can just about see a four-step sequential pipeline, created from a gradient boosting model in SAS Visual Analytics. When this project runs, each step runs in its own separate compute context. Some models run multiple steps at the same time. You should notice a significant improvement in the total 'wall clock' time (as compared to CPU time) when running these models while sufficient pre-started compute servers in the chosen compute context are available and not currently in use.
SAS Studio users are generally familiar with switching compute contexts - click on the compute context icon top-right in SAS Studio to change to a different context:
If you select a compute context which has unused (i.e. available) pre-started compute servers, you should see a very noticeable improvement in how quickly your compute session in SAS Studio is ready to run SAS code.
The tradeoff for this is that the compute session runs as the shared service account, and not as you (or rather, as the signed-in user). This may have some impact on your filesystem permissions, if you access anything on the filesystem, such as base or other path-based libraries, filerefs etc. But the tradeoff may be worth it for the much faster compute session startup time.
So now you know how to script configuration of the compute context from the command line, and can see how easily it could be automated as part of an environment configuration script. Hopefully, that's useful to someone out there.
Thank you to Rob Collum for reviewing this post and for his great comments. Any remaining errors or omissions are mine.
See you next time!
Find more articles from SAS Global Enablement and Learning here.
In the step 1 a account has been created (-u modelservice -p mySecretPassword123).
Can you please clarify if this account is the one that already exists with authentication provider
OR
is it an account created for this purpose and need not exist with the authentication provider. Something like internal account in SAS 9.x.
As I understand it this is the key issue from the above:
"A compute context you configure to have pre-started available compute servers must run those compute servers under a shared service account"
This service account must be defined in the OS (via LDAP etc) as OS processes are run under it. In any case there is no equivalent of internal accounts in Viya because there is no equivalent of SAS 9 metadata repositories.
Thanks @SASKiwi for the response.
Wondering if there are any cost implications when we have a large number of pre started compute servers?
@thesasuser - I suspect the main cost implication would be increased memory usage as each compute server instance will consume memory regardless of whether it has been used or not. I wouldn't expect CPU usage to change much as the overhead of starting a compute server would be low compared to when it is used for processing.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.