[uberconf 2023] Structured Concurrency in Java

Speaker: Venkat Subramaniam

@venkat_s

For more, see the table of contents


Warning

  • Incubator phase feature
  • Anything can change.
  • Will be a year or more before release
  • use –enable-preview flag
  • Java prints out warning using incubator feature whenever run program

Executor Service

  • Since Java 5
  • Executors.newFixedThreadPool(x)
  • executorService.submit() -> logic()) – returns future. Call future.get() when done
  • executorService.shutdown()
  • executorService.awaitTermination(10, TImeout.SECONDS)

Structured Concurrency

  • Allow control of what happens on parallel
  • Parent handles/processes failures from children
  • Currently import jdk.incubator.concurrent – will move
  • StructuredTaskScopeShutdownOnFailure – invoke all
  • StructuredTaskScopeShutdownOnSuccess – invoke any
  • try (var scope = new StructuredTaskScope()) – want autoclose – or scope = StructuredTaskScopeShutdownOnSuccess() or scope = StructuredTaskScopeShutdownOnSuccess<String>()
  • scope.fork(() -> logic()) – makes child tasks, still returns a Future
  • scope.join() – don’t use – better to use a timeout so not unbounded waiting on children
  • scope.joinUntil(Instant.now().plusSeconds(50)) – better, uses timeout. waits for all children up to timeout Nice using Java date math
  • future.resultNow() – get result immediately. (vs get() which waits if not available)
  • scope.throwIfFailed(ex- > handle()) – deal with first failure

Scoped Values

  • ThreadLocal not useful in Spring because thread executing code not the same one that created the value
  • Scoped value, not scoped variable. Immutable
  • Hide the value instead of changing it
  • New value available in inner value. When get back out of that scope, see original value.
  • Doesn’t matter which thread runs the code because matters where you are in code.
  • Useful when calling a lambda which does a callback via third party code
  • Created ScopedValue field in the class that needs the data.
  • ScopedValue.newInstance() – placeholder, doesn’t have value yet
  • state.isBound() – whether has been set to a value
  • ScopedValue.where(state, “test”).run(lamba) – binds the value
  • state.get() – get value if bound. Blows up if not bound

My take

As an incubator feature, I knew nothing about this. It was great to learn about it from a Venkat talk. Different then the usual which is something I do know about and am learning deeper. I also enjoyed the airport code jokes: IAH (Houston – i am here), IAD (Dulles – i am delayed), and ORD (Chicago – ordeal). I’m always impressed Venkat can live code in front of so many people. I’d never seen incubator code in use. Nice it gets a temporary package name; can’t use it by accident. Venkat used IntelliJ to create a module. I don’t think I’ve ever seen him use IntelliJ :). Great audience questions on structured task scope. The scoped value thing made my head swim for a bit, but I get it now.

[uberconf 2023] Jenkins vs GitHub Actions

Speaker: Brent Laster

@BrentCLaster

For more, see the table of contents


GitHub Actions

  • Several years old
  • Actions = framework, actions – building block (ex: checkout code)
  • Automated workflows, call actions
  • Based on repository operations – ex: push, pull, issues comment
  • Can combine/share
  • Migration tool from other CI providers
  • Repository dispatch events – for things not in github. Good for while migrating.
  • Workflows contain jobs, jobs contain steps
  • All public actions: https://github.com/marketplace?type=actions. Anyone could have submitted. See who created. ex; verified creator. Can see source code of any action ex: last updated date, how many creators
  • Can create Docker, JavaScript or composite (multiple workflow steps) as custom actions
  • workflow_dispatch – can start interactively

Cost

  • Free for public repos or self hosted runners (aka running on your servers)
  • For private repos, 2K free minutes per month and 500MB of storage. Minutes restart each month. Storage includes github packages
  • Multiplier if using github hosted runners – linux x1, windows x2, mac x10

Directory

  • .github directory
  • .github/workflows/*.yml

Key differences from Jenkins

  • GitHub Actions run in parallel by default; Jenkins runs serially by default.
  • GitHub Action jobs like Jenkins stages
  • GitHub Action actions are like Jenkins plugins
  • Less config for GItHub Action
  • GitHub Action can have any name; only yaml extension matters. (action.yaml needed for metadata for reuse though)
  • GitHub Action always in github
  • GitHub Action can have different workflows for different events
  • Jenkins supports othe reports
  • Jenkins pipeline stages can run on different nodes
  • GitHub uses reusable workflow where Jenkins uses pipeline libraries. Use workflow_call trigger to call.

Structure

  • on
  • — jobs
    • —- job
      • —— runner
      • —— steps

Code

  • runs-on – what runner to use. Can be custom runner or a GitHub provided/hosted runner. Steps in a job run on the same runner. Fresh VM per job. Docker runners are self hosted.
  • uses – the code as a relative path to the repo. After path to action can have @label for tag/version #/etc
  • on.schedule to run on a schedule – can use cron
  • needs – set dependency to invoke sequentially
  • if: success(), always(), cancelled(), failure()

UI

  • Actions tab lists workflow. Can see runs over time.
  • Like stage view of Jenkins
  • Don’t know of a way to aggregate reporting on an org level [me neither; but worth asking]

Bonus: Online IDE

  • Going to your repo and pressing the period, changes your URL from github.com to github.dev. This shows your repo in VS Code.

Migration

  • Code – move to GitHub if not there – all code/projects, history? branches? Easy to move from one git to another
  • Automation – all projects? Do people know what the Jenkinsfiles do? Custom scripting/kludges? Old versions?
  • Infrastructure – custom setup/config/os versions? Can you switch from Mac/Windows to Linux?
  • Users – what are appropriate permissions? Informed? Trained?
  • Tips – delete outdated/unneeded, standardize where can/make reusable workflow, allow enough time to migrate, require training, do a test conversion
  • Don’t want to migrate unicorns
  • GitHub Actions Importer – tool for bootstrapping migrations, not complete solutions. Attempts to read AzDO/Bamboo/CircleCI/GitLab/Jenkins/Travis. Migrate what can and access what can’t. Docker container runs as extension to GitHub CLI. Has commands: update (to latest version), version, configure (interactive prompt to configure credentials), audit (looks at current footprint), forecast (predicts Actions usages), dry-run, migration (create initial files). Good for insights. Can be more trouble than it’s worth to use in full. Can write custom transformer in Ruby if need something not built in

My take

I’ve used GitHub actions only a tiny bit, but lots of Jenkins. The phrase “like in Jenkins” came up a lot which was helpful in comparing them and learning faster. As were the tables and the code comparisons. The shortcut of “.” is cool (not about actions, but still useful).

UberConf 2023 Table of Contents

This is my first time attending UberConf. It’s a nice conference. Sessions are longer so have time to go deeper. I like that all the rooms have tables/power. And the outside networking space.

Tuesday

  • Venkat did an after dinner keynote called “Decision Dials”. It was great; need for balance. I didn’t blog it, but I enjoyed it.

Wednesday

Thursday

Friday