~/docs
Resonate
Resonate
2.x 2.4.0, current
Torque
Toggle sidebar
Torque
webpatser/torque 2.4.0

Torque 2.x

Upgrade Guide

Upgrade notes for Torque 2.x, from 1.4.x to 2.0.0 and the changes in later 2.x releases, plus older 1.x and 0.x steps.

The master records the installed version in Redis ({prefix}version) and, on the first torque:start after a deploy, runs the data steps for every version between the recorded one and the installed one. Nothing is required from you unless a section below says so. A stored version below 1.4.0 refuses to start (since 2.0.0). torque:status shows the recorded data version next to the installed one.

To preview cleanup of leftovers from older versions before restarting the fleet:

php artisan torque:prune --deep --dry-run
php artisan torque:prune --deep

2.4.0

  • PHP ^8.6 is required; PHP 8.5 is no longer supported.
  • The event loop is webpatser/fledge-loop (Fledge\Loop) instead of revolt/event-loop (Revolt\EventLoop), which Torque no longer requires and which cannot be installed next to it. Code of your own that calls Revolt\EventLoop (job classes, listeners, service providers) has to move to Fledge\Loop: same static methods, no alias layer. Drain queues whose serialized payloads reference Revolt classes before deploying.
  • webpatser/fledge-fiber ^13.43.0.3 is required.
  • New event_loop config key (FLEDGE_EVENT_LOOP). See Configuration.
  • A Composer path repository, Torque as the root package, a branch and 1.0.0+no-version-set now count as a dev install: the upgrade steps run, nothing is recorded in {prefix}version. A key that already holds a bogus 1.0.0 keeps refusing until you run SET {prefix}version 1.4.0.
  • Workers that die within 10 seconds of spawning are respawned with a backoff. See Deployment.

2.3.0

Fleet metrics per host

No data step and no config change. The Redis layout of the fleet aggregate and the cluster gauges changes; only tooling that reads those keys directly has to follow.

  • redis.read_timeout_seconds (default 30) now also applies to the master's own Redis reads.
  • {prefix}metrics is no longer written. Each master writes its host's aggregate to {prefix}metrics:live:{host} (a hash, 30 second TTL) and adds the host to the sorted set {prefix}metrics:live, scored by the publish epoch.
  • Cluster gauges in {prefix}metrics:gauge:{tier} are written per host for avg_latency_ms, concurrent, memory_mb and worker_memory_peak_mb, in fields {bucket}:{host}:{metric}. pending and delayed keep the unscoped field.
  • {prefix}metrics:hosts:first is a new sorted set scored by the epoch a host was first seen.
  • The rollup and gauge prune takes a SET NX claim, {prefix}metrics:prune:{key without prefix}:{bucket}, so one master prunes each shared hash per bucket.
  • New key {prefix}metrics:workers: a sorted set of worker ids scored by last heartbeat, with a 60 second TTL refreshed on every publish.
  • Redis Cluster users must set redis.cluster (TORQUE_CLUSTER=true). Job events now go through one script that touches the event stream and both dashboard indexes; without the flag it is rejected with CROSSSLOT.

External tooling that read HGETALL {prefix}metrics should run ZRANGEBYSCORE {prefix}metrics:live <now - 30> +inf and then HGETALL {prefix}metrics:live:{host} for each member, or call MetricsPublisher::readAggregate($redis, $prefix) in PHP. Tooling that scanned {prefix}worker:* can read ZRANGE {prefix}metrics:workers 0 -1 and HGETALL {prefix}worker:{id}.

Rolling deploy: with old and new masters side by side only the upgraded hosts' aggregates are summed, so the overview undercounts until the last host is upgraded; it never double counts. Hosts that go away drop out of the sums 30 seconds after their last publish.

Prune, flush and autoscaler behaviour

No data step and no config change.

  • torque:prune --deep keeps recent consumers. Without --consumer-idle it deletes only consumers without pending work idle for 3600 seconds. Pass --consumer-idle=0 for the old sweep. The option must be a whole number of seconds, 0 or more.
  • torque:prune follows dead_letter.max_entries: --dead-letter-max no longer defaults to 100000.
  • torque:flush is scoped to the queues it flushes and no longer deletes every {prefix}job:* key. An empty or invalid --queues value exits with an error.
  • The autoscaler grows the fleet to min_workers, one worker per decision, subject to the cooldown. Set workers to at least min_workers if you did not intend that.

1.4.x to 2.0.0

No data step, but not a drop-in upgrade. 2.0.0 refuses to start on data older than 1.4.0, changes when jobs fail for every install, and changes defaults that reach you only in part, depending on your published config/torque.php.

Before you upgrade

  • Get onto 1.4.x first. The master refuses to start when {prefix}version holds a release below 1.4.0: it logs Refusing to start: ... and exits non-zero. Check before the deploy with redis-cli GET {prefix}version. The path: deploy any 1.4.x, start a master once, then deploy 2.0.0.
  • The check passes when nothing is stored, when the stored value is dev, and when Redis is unreachable at start.
  • SET {prefix}version 1.4.0 is the escape hatch. It skips the removed 0.16.0 cleanup and the 1.0.0 delete of {prefix}metrics:buckets; run php artisan torque:prune --deep and DEL {prefix}metrics:buckets afterwards.
  • Install laravel/slack-notification-channel 3.6 or newer if you have it at all. Composer now conflicts with anything below.
  • Decide about published config, and run php artisan config:cache again if you cache config.

New config keys

All optional.

Key Default What it does
release_limit_seconds 86400 Env TORQUE_RELEASE_LIMIT. Seconds a job may keep releasing itself; 0 is off
streams.<name>.release_limit_seconds none Per-stream override; 0 opts that stream out
reload_pause_seconds 10 Env TORQUE_RELOAD_PAUSE. Was part of drain_grace_seconds
timeouts.release_delay_seconds 10 Minimum delay of a job released after its timeout. Was part of drain_grace_seconds
timeouts.settle_seconds 5 Budget of interrupted() and the timeout listeners

New env variables on the shipped default stream: TORQUE_QUEUE, TORQUE_RETRY_AFTER, TORQUE_MAX_RETRIES, TORQUE_BACKOFF, TORQUE_STREAM_TIMEOUT. A published file keeps its literal streams block and ignores them. With TORQUE_QUEUE set, a connection in config/queue.php with a literal 'queue' => 'default' dispatches to a stream nothing consumes, so use env('TORQUE_QUEUE', 'default') there too.

Changed defaults

A key your published file contains keeps its value. A key it lacks takes the new default, and so does an app with no published file. A file published from 1.3 or 1.4 contains all of the keys below, so it flips none of them until you act.

Key 1.x default 2.0 default To adopt in a 1.4.x published file To keep 1.x where it would flip
strict_attempts false true TORQUE_STRICT_ATTEMPTS=true TORQUE_STRICT_ATTEMPTS=false
timeouts.enabled false true TORQUE_TIMEOUTS=true TORQUE_TIMEOUTS=false
memory_limit 0 512 TORQUE_MEMORY_LIMIT=512 TORQUE_MEMORY_LIMIT=0
loop_stall_kill_seconds 0 null, derived Copy the shipped line, or TORQUE_LOOP_STALL_KILL=300 TORQUE_LOOP_STALL_KILL=0
drain_grace_seconds 10 null, derived Copy the shipped line and unset the env variable TORQUE_DRAIN_GRACE=10 (logs a WARN)
dashboard.enabled true false Set false if you want it off TORQUE_DASHBOARD=true

Copy the shipped lines rather than only dropping the fallback: (int) env('TORQUE_DRAIN_GRACE') is a grace of 0, not a derived one. Merge by hand instead of vendor:publish --force, which overwrites your streams. The release limit is the exception: no 1.x file has the key, so it applies to every install on the first deploy.

Renamed config keys

Rename these in config/torque.php now. In 2.x the old key still works: its value moves to the new key at boot, the old key wins if the file has both, and the master logs WARN Renamed config keys in use. Torque 3.0 makes this a boot failure.

Old key New key Env
coroutines_per_worker slots_per_worker TORQUE_COROUTINES to TORQUE_SLOTS_PER_WORKER
block_for poll_interval_ms TORQUE_BLOCK_FOR to TORQUE_POLL_INTERVAL_MS
redis.read_timeout redis.read_timeout_seconds unchanged
takeover_ready_timeout takeover_ready_timeout_seconds unchanged
job_streams job_events none
job_limits (job or stream) honour_job_limits (bool, stream maps to false) TORQUE_JOB_LIMITS to TORQUE_HONOUR_JOB_LIMITS

Old env variables keep working silently in the shipped file through 2.x. A published file still on an old key reads only the old env variable. Code that reads config('torque.coroutines_per_worker') now gets null. A queue connection's own block_for in config/queue.php and the --coroutines CLI flag keep their names.

Behaviour changes

  • Strict attempts: leave headroom in $tries. Jobs are checked before they run and fail without running once past their tries or retryUntil. A delivery after a worker went away counts too and ends with reason redelivery_limit.
  • Job timeouts: audit every $timeout in your job classes before enabling. Those values were ignored until now. A job with no $timeout on a stream with no timeout still has no limit. A job past its limit is failed or retried, which counts as a try, and its whole worker rotates (exit 1).
  • Memory limit: check the ini value of the process running workers. A worker at 512 MB real memory drains and exits with status 12. When ini memory_limit is lower, PHP fatals first, taking every slot with it; the boot WARN PHP memory_limit is ... is the only signal. The CLI default of 128M triggers it.
  • Release limit: $tries no longer ends a releasing job, time does. On every install self-releases stop counting against tries and count against release_limit_seconds. Past the limit the job fails with MaxAttemptsExceededException, runs failed() and reaches the dead letter with reason release_limit. Check jobs that poll with $tries plus release(): add a retryUntil, or count in the job. Opt out with $tries = 0, release_limit_seconds = 0 or streams.<name>.release_limit_seconds = 0. Drain rate-limited queues on 1.4.x first, since a job released under 1.x can fail on its first delivery after the upgrade. Many jobs reaching the deadline together can trip the circuit breaker; set 'circuit_breaker' => false on a stream where that is unwanted. WithoutOverlapping with its default releaseAfter = 0 still spins; give it a releaseAfter.
  • Drain: regenerate your Supervisor config. drain_grace_seconds used to do four jobs and is split into grace, reload pause, release delay and settle. Null grace derives min(300, longest stream timeout or retry_after), 60 at package defaults, instead of 10. Run php artisan torque:supervisor --path=... after the upgrade, then supervisorctl reread && supervisorctl update. An old stopwaitsecs of 60 SIGKILLs a 60-second drain. A pinned grace is not corrected for you; every worker logs WARN drain_grace_seconds is 10s, below the 60s derived ... once at boot.
  • cache:clear no longer drains workers. When the illuminate:queue:restart key goes from set to gone a worker logs one line and keeps running. Call queue:restart or torque:reload in deploy scripts, and run queue:restart after any cache clear.
  • Stall watchdog: decide whether you accept it. Blocking PDO queries, CPU-bound fibers and sync clients block the loop, so they kill their worker and every sibling slot. WARN Loop stall watchdog appears at boot on database-cache apps, because worker timers read the default cache synchronously.
  • Dashboard off by default. Without a published config the dashboard routes are gone after the upgrade; set TORQUE_DASHBOARD=true to keep them. A published file has the literal true, which does not flip.

API changes

The public API is the Torque facade, Stream\Streamable, JobStream, JobStreamRecorder, Support\StreamQueueResolver, Contracts\Silenced, Events\*, the torque connection through Queue::, the torque:* commands and the config keys. Everything else may change without a major version.

  • StreamQueue, StreamJob and WorkerProcess are now @internal.
  • UpgradeRunner: LEGACY_BUCKETS_SUFFIX and the 0.16.0 and 1.0.0 steps are removed, the constructor lost its StreamHousekeeper argument, and MINIMUM_STORED_VERSION and assertUpgradePath() are new.
  • WorkerId::parse() no longer reads the {host}-{pid} form.
  • The legacy Slack branch in LongWaitNotification is removed.
  • New StreamJob::triesUsed(), releases(), releaseDeadline(), retryAfterFailure(); StreamQueue::retryAfterFailure(), releaseLimitSeconds(); Support\DrainSettings; Support\LegacyConfig.

After the first deploy, look in the log for Refusing to start, WARN Renamed config keys, WARN Loop stall watchdog, WARN PHP memory_limit and WARN drain_grace_seconds.

Rollback to 1.4.x should work but is reasoned, not tested: the extra payload fields look harmless to 1.x. Revert config/torque.php with the code. Jobs that released under 2.0 keep their high attempts, so under 1.x with strict_attempts on they can fail on delivery.

1.3.x to 1.4.0

No data step. Upgrade promptly: the dashboard's viewTorque gate was not checked on Livewire update requests in v0.12.0 through v1.3.0, so a user holding a valid page snapshot could keep calling dashboard actions, including dead-letter retry and purge. 1.4.0 checks the gate on every mount and update and fails closed.

New optional keys: waits, silenced, silenced_tags. The Batches page needs php artisan make:queue-batches-table.

  • A self-release no longer records completed. A job failed with fail() no longer records completed after failed. A permanently failed job's status is failed rather than exception.
  • A job waiting longer than the job event TTL loses its queued event.
  • Tags exist only on jobs dispatched after the upgrade.
  • Long-wait alerts run in a child process. Register LongWaitDetected listeners in a service provider.

1.2.x to 1.3.0

No data step. New optional keys: timeouts.enabled (then false), streams.<name>.timeout, loop_stall_kill_seconds (then 0).

  • Entries returned at drain go to the tail of the stream, so processing order changes, in every mode.
  • Redelivery bookkeeping runs in every mode; counting and the dead-letter reason apply only under strict_attempts.
  • Queue::popUsing('torque', ...) is supported; register under torque.

1.1.x to 1.2.0

No data step. New optional keys: job_limits (now honour_job_limits), strict_attempts (then false), memory_limit (then 0), force, redis.read_timeout.

  • While the app is down (artisan down), slots stop polling and claiming. Set force to true (TORQUE_FORCE) to keep processing.
  • A job's retryUntil, $tries, maxExceptions and $backoff take over from the stream's max_retries and backoff; $tries = 0 means unlimited. Exponential retries (2**attempts) are capped at 1 hour.
  • size() is now waiting plus delayed plus reserved, and pendingSize() is waiting only, as in the stock Redis queue. Autoscalers and alerts built on these numbers see new values.
  • JobExceptionOccurred fires after JobFailed on the fail path.
  • New events: WorkerStarting, WorkerStopping, WorkerIdle, WorkerQueuePaused, WorkerQueueResumed, JobPopping, JobPopped, JobReleased and JobReleasedAfterException. JobPopping fires on every poll, about 25 per second at 50 slots, so keep its listeners cheap.
  • Per-attempt isolation grew: Log context, Auth guards and Cache::memo().

0.18.x to 1.0.0

1.0.0 is the first stable release. Coming from 0.15.x or older, upgrade to any 0.16, 0.17 or 0.18 release first and start the master once. A 1.0.0 data step deletes {prefix}metrics:buckets on the first torque:start. StreamHousekeeper::deepClean() returns a worker_hashes count in place of legacy_keys.

0.17.x to 0.18.0

  • Requires illuminate/* ^13.34 and webpatser/fledge-fiber ^13.38.
  • #[CountCrashesAsExceptions] is honoured. Set each stream's retry_after longer than its longest job, or a job stolen through XAUTOCLAIM while still running is counted as a crash.
  • push() and later() return ?string: null for an afterCommit job dispatched inside a transaction.
  • igbinary payloads are only decoded when torque.serializer is igbinary. Drain the queues before switching serializers.
  • The dashboard redacts more, the master refuses a symlinked storage/torque.lock, and queue enumeration uses SCAN instead of KEYS.

0.16.x to 0.17.0

Nothing to migrate. New optional key dashboard.default_range (1h). The dashboard has one time range for every screen, picked in the topbar and remembered for the session; the workers screen is grouped by host, and the queues screen is range-scoped.

0.15.x to 0.16.0

A one-off cleanup of leftovers runs on the first start. Ongoing housekeeping runs every dead_letter.prune_interval seconds. New keys: dead_letter.max_entries, dead_letter.prune_interval, circuit_breaker.*, metrics.retention (was 3600), metrics.rollups.*, dashboard.gauge_max. Dead-letter entries beyond max_entries are evicted oldest first; schedule queue:prune-failed --hours=168 for the failed_jobs table. Set maxmemory and maxmemory-policy noeviction on the Redis instance.

Coming from Horizon

Horizon Torque
horizon torque:start
horizon:status torque:status, torque:monitor for a live view
horizon:pause / horizon:continue torque:pause / torque:pause continue
horizon:terminate torque:stop (graceful), torque:reload (zero-downtime takeover)
horizon:forget {id} --all torque:forget {id?} {--all} {--queue=} {--force}
horizon:clear queue:clear
horizon:supervisor None; one master runs the fleet. torque:supervisor generates a Supervisor config for the master
horizon:snapshot None; the master publishes metrics itself
Supervisors, maxProcesses workers processes, each with slots_per_worker Fiber slots
balance / autoscaling Slot-pressure autoscaling, per-stream max_concurrency
tries, backoff A job's own properties, then streams.<q>.max_retries and backoff
timeout Job $timeout, then streams.<q>.timeout
memory memory_limit
trim / failed job retention dead_letter.ttl and max_entries, metrics.retention
Tags, silenced, long-wait waits Tags, silenced, silenced_tags and waits
Environments env() in config/torque.php and prefix

Jobs need no change. Torque is a queue connection (QUEUE_CONNECTION=torque), so dispatching, batches and chains work as before.