Created
September 28, 2021 15:59
-
-
Save bdelacretaz/5ece181782206c0c9f820a78e6baaeef to your computer and use it in GitHub Desktop.
Script to test Apache Sling Repoinit with many operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
/* | |
Demo script for my adaptTo 2021 talk, on Apache Sling repoinit: | |
https://adapt.to/2021/en/schedule/repoinit-a-mini-language-for-content-repository-initialization.html | |
Generate and execute a number (see "limit" below) of repoinit statements. | |
To use this, save this script as repoinit.esp, create | |
a node with a unique resource type that points to it | |
and request that node with the appropriate extension: | |
curl -u admin:admin -F sling:resourceType=repoinit http://localhost:8080/content/repoinit | |
curl -X MKCOL -u admin:admin http://localhost:8080/apps/repoinit | |
curl -u admin:admin -T repoinit.esp http://localhost:8080/apps/repoinit/repoinit.esp | |
curl http://localhost:8080/content/repoinit.repoinit | |
Results on my 2018 macbook pro with Java 11, running the default Sling Starter | |
setup with Oak/tar persistence: | |
with limit = 999: | |
3996 repoinit operations executed successfully. | |
999 paths should have been created under /tmp/repoinit-one. | |
Elapsed time for script generation: 3 msec. | |
Elapsed time for repoinit parsing: 13 msec. | |
Elapsed time for repoinit operations execution: 4685 msec. | |
with limit = 2500: | |
10000 repoinit operations executed successfully. | |
2500 paths should have been created under /tmp/repoinit-two. | |
Elapsed time for script generation: 9 msec. | |
Elapsed time for repoinit parsing: 34 msec. | |
Elapsed time for repoinit operations execution: 11862 msec. | |
second execution with limit = 2500, paths already created: | |
10000 repoinit operations executed successfully. | |
2500 paths should have been created under /tmp/repoinit-two. | |
Elapsed time for script generation: 10 msec. | |
Elapsed time for repoinit parsing: 31 msec. | |
Elapsed time for repoinit operations execution: 4863 msec. | |
with limit = 5000: | |
20000 repoinit operations executed successfully. | |
5000 paths should have been created under /tmp/repoinit-three. | |
Elapsed time for script generation: 16 msec. | |
Elapsed time for repoinit parsing: 127 msec. | |
Elapsed time for repoinit operations execution: 23868 msec. | |
second execution with limit = 5000, paths already created: | |
20000 repoinit operations executed successfully. | |
5000 paths should have been created under /tmp/repoinit-three. | |
Elapsed time for script generation: 16 msec. | |
Elapsed time for repoinit parsing: 60 msec. | |
Elapsed time for repoinit operations execution: 9941 msec. | |
*/ | |
var scriptStart = new Date(); | |
var base = "/tmp/repoinit-three"; | |
var limit = 5000; | |
var script = ""; | |
for(i=1 ; i <= limit; i++) { | |
var user = "LU-" + i; | |
var path = base + "/mod-" + i % 256 + "/lu-" + i; | |
var EOL = "\n"; | |
script += "create service user " + user + EOL | |
+ "create path " + path + EOL | |
+ "set ACL for " + user + EOL + "allow jcr:all on " + path + EOL + "end" + EOL | |
+ "set ACL on " + path + EOL + "deny jcr:read for everyone" + EOL + "end" + EOL | |
; | |
} | |
var parsingStart = new Date(); | |
var parser = sling.getService(Packages.org.apache.sling.repoinit.parser.RepoInitParser); | |
var ops = parser.parse(new Packages.java.io.StringReader(script)); | |
var processingStart = new Date(); | |
var processor = sling.getService(Packages.org.apache.sling.jcr.repoinit.JcrRepoInitOpsProcessor); | |
var repository = sling.getService(Packages.org.apache.sling.jcr.api.SlingRepository); | |
var admin = new Packages.java.lang.String("admin"); | |
var creds = new Packages.javax.jcr.SimpleCredentials(admin, admin.toCharArray()); | |
var session = repository.login(creds); | |
processor.apply(session, ops); | |
session.save(); | |
var processingDone = new Date(); | |
%> | |
<%= ops.size() %> repoinit operations executed successfully. | |
<%= limit %> paths should have been created under <%= base %>. | |
Elapsed time for script generation: <%= parsingStart - scriptStart %> msec. | |
Elapsed time for repoinit parsing: <%= processingStart - parsingStart %> msec. | |
Elapsed time for repoinit operations execution: <%= processingDone - processingStart %> msec. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment