Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Ruby Delegate Usage with Java Delegate Usage #9

Open
kaladay opened this issue Sep 24, 2024 · 0 comments
Open

Replace Ruby Delegate Usage with Java Delegate Usage #9

kaladay opened this issue Sep 24, 2024 · 0 comments
Labels
story A user story or similar.

Comments

@kaladay
Copy link

kaladay commented Sep 24, 2024

Cantaloupe is running under Java.

There is overhead to have the Ruby be started up and executed within Java.
This is done for every request in which the Ruby delegate is used.

This may also open up an avenue for programming very specific use cases for TAMU in a delegate itself.

If we aren't using a custom delegate, then it may make sense to disable the Ruby Delegate and set the Java Delegate as a default to save time that is being incurred on every transform. (We are using a custom delegate.)

The delegate script is a file containing a delegate class written in Ruby. The class is instantiated per-request, early in the request cycle, and disposed of at the end of the request cycle. At various points in the request cycle, its methods are called by the application to obtain information needed to service the request.

Set delegate_script.enabled to false.
This appears to be the default, but the logs show otherwise.
(Try also looking into setting every lookup_strategy such as FilesystemSource.lookup_strategy.)

The delegate appears to be in use via:

  def httpsource_resource_info(options = {})
    id = context['identifier']
    if ( id =~ /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ )
      uri = 'https://api-pre.library.tamu.edu/iiif-service/resources/' + id + '/redirect'
    elsif
      irid = Base64.decode64(CGI.unescape(id))
      if irid.include? ":"
        parts = irid.split(':')
        ir = parts[0]
        path = parts[1]
        if ir == 'fedora'
          uri = 'https://api-pre.library.tamu.edu/fcrepo/rest/' + path
        elsif ir == 'dspace'
          uri = 'https://oaktrust-pre.library.tamu.edu/' + path
        else
          uri = irid
        end
      else
        uri = id
      end
    end
    return uri
  end

This can be replaced with a Java Delegate equivalent.
These URIs should be configurable via environment variables to be docker-compatible.

Example LOG showing Ruby Delegate usage:

16:09:17.200 [qtp1594199808-20] INFO  me.i.l.c.r.i.v.ImageResource - Handling GET /iiif/2/eac40814-fa1c-357d-890d-767a0c325cb2/full/full/2/default.png
16:09:17.200 [qtp1594199808-20] DEBUG me.i.l.c.r.i.v.ImageResource - Base URI from assembled from base_uri key: https://api-dev.library.tamu.edu
16:09:17.200 [qtp1594199808-20] DEBUG me.i.l.c.d.DelegateProxyService - Instantiating a JRubyDelegateProxy
16:09:17.202 [qtp1594199808-20] DEBUG me.i.l.c.i.MetaIdentifier - [Raw path component: eac40814-fa1c-357d-890d-767a0c325cb2] -> [decoded: eac40814-fa1c-357d-890d-767a0c325cb2] -> [slashes substituted: eac40814-fa1c-357d-890d-767a0c325cb2]
16:09:17.202 [qtp1594199808-20] DEBUG me.i.l.c.i.Identifier - [Raw path component: eac40814-fa1c-357d-890d-767a0c325cb2] -> [decoded: eac40814-fa1c-357d-890d-767a0c325cb2] -> [slashes substituted: eac40814-fa1c-357d-890d-767a0c325cb2]
16:09:17.204 [qtp1594199808-20] DEBUG me.i.l.c.c.InfoService - getInfo(): retrieved from InfoCache: eac40814-fa1c-357d-890d-767a0c325cb2
16:09:17.205 [qtp1594199808-20] DEBUG me.i.l.c.c.FilesystemCache - newDerivativeImageInputStream(): hit: eac40814-fa1c-357d-890d-767a0c325cb2_1:1_rotate:2_encode:png_UNDEFINED_8_e95198c48292fa4c8fc0617e850c1f6d (/var/cache/cantaloupe/image/71/1a/df/711adff9f0b80a9ac454ae71a31275f2_d6a46df8c7b3d211956d108134f003ec.png)
16:09:17.205 [qtp1594199808-20] DEBUG me.i.l.c.r.i.v.ImageResource - Base URI from assembled from base_uri key: https://api-dev.library.tamu.edu
16:09:17.265 [qtp1594199808-20] DEBUG me.i.l.c.r.InputStreamRepresentation - Streamed from the cache without resolving in 60 msec

WARNING: I noticed that when I setup the environment variables for the Scripting Delegate in the Docker container, somehow the delegates.rb file got recreated. Whatever the configuration was got lost.

Note from the documentation:

Unlike the delegate script, a sample Java delegate is not bundled with the application.

see: https://github.com/cantaloupe-project/sample-java-delegate
see: https://cantaloupe-project.github.io/manual/5.0/delegate-system.html
see: https://cantaloupe-project.github.io/manual/5.0/delegate-system.html#Java%20Delegate
see: https://cantaloupe-project.github.io/manual/5.0/delegate-system.html#Improving%20Efficiency
see: https://github.com/cantaloupe-project/cantaloupe/blob/3722b075f71eea4e2560e0c0fdc6ceb580db37ee/cantaloupe.properties.sample#L80
see: https://github.com/cantaloupe-project/cantaloupe/blob/develop/src/main/java/edu/illinois/library/cantaloupe/delegate/JRubyDelegateProxy.java
see: https://github.com/cantaloupe-project/cantaloupe/blob/develop/src/main/java/edu/illinois/library/cantaloupe/delegate/JavaDelegateProxy.java
see: https://github.com/cantaloupe-project/cantaloupe/blob/3722b075f71eea4e2560e0c0fdc6ceb580db37ee/src/main/java/edu/illinois/library/cantaloupe/source/LookupStrategy.java#L14
see: https://github.com/cantaloupe-project/cantaloupe/blob/3722b075f71eea4e2560e0c0fdc6ceb580db37ee/cantaloupe.properties.sample#L155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
story A user story or similar.
Projects
None yet
Development

No branches or pull requests

1 participant