You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Chetan Mehrotra (JIRA)" <ji...@apache.org> on 2014/07/02 20:11:24 UTC

[jira] [Commented] (SLING-913) Add a cache for pre-compiled scripts

    [ https://issues.apache.org/jira/browse/SLING-913?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14050497#comment-14050497 ] 

Chetan Mehrotra commented on SLING-913:
---------------------------------------

Ran the Apache Benchmark [1] after installing the espblog sample. Following command was used

bq. ab -k -n 100 -c 20 -A admin:admin http://localhost:8080/content/espblog/*.html

*Default*
{noformat}
Benchmarking localhost (be patient).....done


Server Software:        Jetty(7.x.y-SNAPSHOT)
Server Hostname:        localhost
Server Port:            8080

Document Path:          /content/espblog/*.html
Document Length:        1317 bytes

Concurrency Level:      20
Time taken for tests:   0.945 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100
Total transferred:      148900 bytes
HTML transferred:       131700 bytes
Requests per second:    105.87 [#/sec] (mean)
Time per request:       188.916 [ms] (mean)
Time per request:       9.446 [ms] (mean, across all concurrent requests)
Transfer rate:          153.94 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       1
Processing:    61  183 105.4    164     899
Waiting:       61  183 105.4    164     899
Total:         61  183 105.5    164     900

Percentage of the requests served within a certain time (ms)
  50%    164
  66%    191
  75%    211
  80%    237
  90%    254
  95%    283
  98%    713
  99%    900
 100%    900 (longest request)

{noformat}

*With Script Cache*

{noformat}
Server Software:        Jetty(7.x.y-SNAPSHOT)
Server Hostname:        localhost
Server Port:            8080

Document Path:          /content/espblog/*.html
Document Length:        1317 bytes

Concurrency Level:      20
Time taken for tests:   0.350 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Keep-Alive requests:    100
Total transferred:      148900 bytes
HTML transferred:       131700 bytes
Requests per second:    285.61 [#/sec] (mean)
Time per request:       70.025 [ms] (mean)
Time per request:       3.501 [ms] (mean, across all concurrent requests)
Transfer rate:          415.31 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0       1
Processing:    13   67  36.7     57     202
Waiting:       13   67  36.7     57     202
Total:         13   67  36.9     57     203

Percentage of the requests served within a certain time (ms)
  50%     57
  66%     76
  75%     86
  80%     99
  90%    125
  95%    137
  98%    168
  99%    203
 100%    203 (longest request)

{noformat}

So the Request per second (TPS) jumps from 105 to 285 indicating the caching of scripts should give improved performance

[1] http://httpd.apache.org/docs/2.2/programs/ab.html

> Add a cache for pre-compiled scripts
> ------------------------------------
>
>                 Key: SLING-913
>                 URL: https://issues.apache.org/jira/browse/SLING-913
>             Project: Sling
>          Issue Type: New Feature
>          Components: Scripting
>    Affects Versions: Scripting Core 2.0.2
>            Reporter: Felix Meschberger
>         Attachments: SLING-913.patch
>
>
> The Java Scripting API provides support for scripting langugages which may precompile script source and reuse the precompiled scripts:
>   javax.script.Compilable: May be implemented by a ScriptEngine if precompilation is
>           supported
>   javax.script.CompiledScript: Result of calling the Compilable.compile method.
> The CompiledScript can be called to repeatedly execute the script without the need for recompilation and thus for improved performance.
> The Sling Core Scripting support should make use of this functionality by maintaining a cache compiled scripts with the following properties
>   * indexed by script path
>   * size limited (using LinkedHashMap overwriting the removeEldestEntry method)
>   * entries are weak or soft references ot cache entries
> A cache entry consists of the following information:
>   * The CompiledScript instance
>   * The time of last compilation. this is compared to the last modification time of the script to decide on whether to recompile
> We might probaly also try to add a reference to the script engine implementation bundle to only use the cache entry if the bundle has not been stopped since adding the cache entry
> Executing the script would then consist of the following steps:
>   1 Check the cache of precompiled scripts. if an entry exists and can be used, use it
>   2. if the ScriptEngine is Compilable:
>       2a. Compile the script and add it to the cache and use it
>       2b. Otherwise have the script engine execute the script



--
This message was sent by Atlassian JIRA
(v6.2#6252)