MLE-30316 Allow configurable socket timeout for classification requests in Flux#649
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a configurable socket timeout for Semaphore classifier requests so large/complex document classification can exceed the current fixed 10s default, while preserving existing behavior when the option isn’t set.
Changes:
- Added
ClassifierOptions.socketTimeout(int)to the Java API and implemented it inClassifierParams. - Added a new CLI option
--classifier-timeoutand wired it through to Spark connector options asWRITE_CLASSIFIER_SOCKET_TIMEOUT. - Updated unit tests and documentation to cover and describe the new option.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| flux-cli/src/main/java/com/marklogic/flux/api/ClassifierOptions.java | Adds the new public API method for configuring classifier socket timeout. |
| flux-cli/src/main/java/com/marklogic/flux/impl/importdata/ClassifierParams.java | Adds the --classifier-timeout CLI flag and forwards the value into the Spark connector options map. |
| flux-cli/src/test/java/com/marklogic/flux/impl/importdata/ClassifierOptionsTest.java | Extends tests to verify the new option is mapped, and verifies the default behavior (key absent when not set). |
| flux-cli/src/test/java/com/marklogic/flux/impl/copy/CopyOptionsTest.java | Updates copy command option parsing/assertions to include the new classifier timeout option. |
| docs/import/classifier.md | Documents --classifier-timeout in the classifier options table. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
rjrudin
left a comment
There was a problem hiding this comment.
I would do seconds here as well and add a connection timeout, which means I would do --classifier-socket-timeout and --classifier-connection-timeout. The expectation is that the user is familiar with Semaphore and thus would be familiar with the two timeout settings that Semaphore provides.
Switched from milliseconds to seconds. Renamed --classifier-timeout -> --classifier-socket-timeout Added --classifier-connection-timeout
| | `--classifier-api-key` | Provide the API key for accessing the classifier service when hosted in Progress Data Cloud. | | ||
| | `--classifier-token-path` | Specify the path to the token generator for the classifier service when hosted in Progress Data Cloud. | | ||
| | `--classifier-batch-size` | Set the number of documents or text chunks to send in a single request to the classifier. Defaults to 20. | | ||
| | `--classifier-socket-timeout` | Set the socket timeout in seconds for classification requests. | |
There was a problem hiding this comment.
I recommend including the default values here, as they're mentioned for other options above and I think a user would naturally wonder what they are and whether they should use something else.
There was a problem hiding this comment.
Added the defaults to the 2 new options
Problem
The Semaphore classifier client had a hardcoded 10-second socket timeout with no way to override it. Classifying large or complex documents (e.g., PDFs with forced language settings) can exceed this limit, and there was no CLI option or Java API method available to raise it.
Solution
Added
--classifier-timeoutas a new CLI option andsocketTimeout(int)as a new method on theClassifierOptionsJava API. The value is passed through to the Spark Connector asspark.marklogic.write.classifier.socketTimeout, where it is applied to the SemaphoreClassificationConfiguration.When the option is not set, no value is forwarded to the connector and the Semaphore library's default of 10,000 ms is preserved — no behavior change for existing users.
Changes
ClassifierOptions.java (public API)
socketTimeout(int socketTimeoutMs)method (@since 2.1.2).ClassifierParams.java
--classifier-timeoutpicocli option (Integer socketTimeoutMs, defaults tonullso no entry is added to the options map when not specified).Options.WRITE_CLASSIFIER_SOCKET_TIMEOUTintomakeOptions()viaOptionsUtil.integerOption().socketTimeout(int)from theClassifierOptionsinterface.ClassifierOptionsTest.java
testOptions()— updated to assertWRITE_CLASSIFIER_SOCKET_TIMEOUTis correctly mapped whensocketTimeout(30000)is called.defaultTimeoutNotIncludedWhenNotSet()— new test verifying the option key is absent from the options map whensocketTimeoutis never called.CopyOptionsTest.java
--classifier-timeout 60000to the copy command classifier options test and the correspondingassertOptions()assertion.classifier.md
--classifier-timeoutrow to the options table.Testing
Unit tests only — no MarkLogic instance required.
All tests pass.
Notes
ClassifierOptionsinterface change is purely additive — no breaking change to the public API.WRITE_CLASSIFIER_SOCKET_TIMEOUTis available at compile time. MLE-30316 Allow configurable socket timeout for classification requests in Flux marklogic-spark-connector#666Jira Story: https://progresssoftware.atlassian.net/browse/MLE-30316