Skip to content

Commit

Permalink
Ability to disable lock persistence on every step (#516)
Browse files Browse the repository at this point in the history
* Add system property DISABLE_SAVE

* disable save

* Update LockableResourcesManager.java

* Cache system property

* Update LockableResourcesManager.java
  • Loading branch information
mPokornyETM authored Aug 7, 2023
1 parent a6f2fc2 commit 0c52865
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,33 @@ To allow this behavior start jenkins with option `-Dorg.jenkins.plugins.lockable
System.setProperty("org.jenkins.plugins.lockableresources.ENABLE_NODE_MIRROR", "true");
```

note: When the node has been deleted, during the lockable-resource is locked / reserved / queued, then the lockable-resource will be NOT deleted.
> *Note:* When the node has been deleted, during the lockable-resource is locked / reserved / queued, then the lockable-resource will be NOT deleted.
----

## Improve performance

To be safe thread over all jobs and resources, need to be all operations synchronized.
This might lead to slow down your jobs. The jenkins self, has low CPU usage, but your jobs are very slow. Why?

The most time are spend to write the lockable-resources states into local file system. This is important to get the correct state after Jenkins reboots.

To eliminate this saving time has been added a property *DISABLE_SAVE*.

+ The best way is to use it with JCaC plugin. So you are sure, you have still correct
resources on Jenkins start.
+ When you set pipeline durability level to *PERFORMANCE_OPTIMIZED*, it makes also sense to set this property to true.

> *Note:* Keep in mind, that you will lost all your manual changes!
> *Note:* This option is experimental. It has been tested in many scenarios, but no body know.
To allow this behavior start jenkins with option `-Dorg.jenkins.plugins.lockableresources.DISABLE_SAVE=true` or run this groovy code.

```groovy
System.setProperty("org.jenkins.plugins.lockableresources.DISABLE_SAVE", "true");
```

## Configuration as Code

This plugin can be configured via
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@
import java.util.stream.Collectors;
import jenkins.model.GlobalConfiguration;
import jenkins.model.Jenkins;
import jenkins.util.SystemProperties;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.jenkins.plugins.lockableresources.queue.LockableResourcesCandidatesStruct;
import org.jenkins.plugins.lockableresources.queue.LockableResourcesStruct;
import org.jenkins.plugins.lockableresources.queue.QueuedContextStruct;
import org.jenkins.plugins.lockableresources.util.Constants;
import org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SecureGroovyScript;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.kohsuke.accmod.Restricted;
Expand All @@ -61,6 +63,9 @@ public class LockableResourcesManager extends GlobalConfiguration {
*/
private List<QueuedContextStruct> queuedContexts = new ArrayList<>();

// cache to enable / disable saving lockable-resources state
private int enableSave = -1;

@SuppressFBWarnings(value = "MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR",
justification = "Common Jenkins pattern to call method that can be overridden")
public LockableResourcesManager() {
Expand Down Expand Up @@ -1267,7 +1272,17 @@ public static LockableResourcesManager get() {

@Override
public synchronized void save() {
if (BulkChange.contains(this)) return;
if (enableSave == -1)
{
// read system property and chache it.
enableSave = SystemProperties.getBoolean(Constants.SYSTEM_PROPERTY_DISABLE_SAVE) ? 0 : 1;
}

if (enableSave == 0)
return; // savinig is disabled

if (BulkChange.contains(this))
return; // no change detected

try {
getConfigFile().write(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
package org.jenkins.plugins.lockableresources.util;

public class Constants {
/// Enable mirror nodes to lockable-resources
public static final String SYSTEM_PROPERTY_ENABLE_NODE_MIRROR = "org.jenkins.plugins.lockableresources.ENABLE_NODE_MIRROR";
/// Disable saving lockable resources states, properties ... into local file system.
/// This option makes the plugin much faster (everything is in cache) but
/// **Keep in mind, that you will lost all your manual changed properties**
/// The best way is to use it with JCaC plugin.
public static final String SYSTEM_PROPERTY_DISABLE_SAVE = "org.jenkins.plugins.lockableresources.DISABLE_SAVE";
}

0 comments on commit 0c52865

Please sign in to comment.