Skip to content

Commit

Permalink
Expose Casandra Request Timeout Config Option
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderkiel committed May 18, 2021
1 parent 41983a8 commit 099d14c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
1 change: 1 addition & 0 deletions docs/deployment/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ The distributed storage variant only uses the index database locally.
| DB_CASSANDRA_PASSWORD | cassandra | v0.11 | | The password for the Cassandra authentication. |
| DB_CASSANDRA_KEY_SPACE | blaze | v0.8 | | The Cassandra key space were the `resources` table is located. |
| DB_CASSANDRA_PUT_CONSISTENCY_LEVEL | TWO | v0.8 | | Cassandra consistency level for resource put (insert) operations. Has to be set to `ONE` on a non-replicated keyspace. |
| DB_CASSANDRA_REQUEST_TIMEOUT | 2000 | v0.11 | | Timeout in milliseconds for all requests to the Cassandra cluster. |

¹ Deprecated, ² In the JAR variant. The Docker image uses a directory below the `/app/data` directory.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@
::username ::password
::put-consistency-level
::max-concurrent-read-requests
::max-read-request-queue-size]))
::max-read-request-queue-size
::request-timeout]))


(defn- init-msg [contact-points put-consistency-level]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns blaze.db.resource-store.cassandra.config
(:require
[clojure.string :as str])
[clojure.string :as str]
[java-time :as jt])
(:import
[com.datastax.oss.driver.api.core.config OptionsMap TypedDriverOption]
[java.net InetSocketAddress]))
Expand All @@ -10,13 +11,16 @@


(defn options
[{:keys [max-concurrent-read-requests max-read-request-queue-size]
[{:keys [max-concurrent-read-requests max-read-request-queue-size
request-timeout]
:or {max-concurrent-read-requests 1024
max-read-request-queue-size 100000}}]
max-read-request-queue-size 100000
request-timeout 2000}}]
(doto (OptionsMap/driverDefaults)
(.put TypedDriverOption/REQUEST_THROTTLER_CLASS "ConcurrencyLimitingRequestThrottler")
(.put TypedDriverOption/REQUEST_THROTTLER_MAX_CONCURRENT_REQUESTS (int max-concurrent-read-requests))
(.put TypedDriverOption/REQUEST_THROTTLER_MAX_QUEUE_SIZE (int max-read-request-queue-size))))
(.put TypedDriverOption/REQUEST_THROTTLER_MAX_QUEUE_SIZE (int max-read-request-queue-size))
(.put TypedDriverOption/REQUEST_TIMEOUT (jt/millis request-timeout))))


(defn build-contact-points [contact-points]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@

(s/def :blaze.db.resource-store.cassandra/max-read-request-queue-size
nat-int?)


;; in milliseconds
(s/def :blaze.db.resource-store.cassandra/request-timeout
pos-int?)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
(:require
[blaze.db.resource-store.cassandra.config :as c]
[clojure.spec.test.alpha :as st]
[clojure.test :as test :refer [deftest are testing]])
[clojure.test :as test :refer [deftest are testing]]
[java-time :as jt])
(:import
[com.datastax.oss.driver.api.core.config OptionsMap TypedDriverOption]
[java.net InetSocketAddress]))
Expand Down Expand Up @@ -31,11 +32,15 @@
1024

TypedDriverOption/REQUEST_THROTTLER_MAX_QUEUE_SIZE
100000)))
100000

TypedDriverOption/REQUEST_TIMEOUT
(jt/millis 2000))))

(testing "custom values"
(let [^OptionsMap options (c/options {:max-concurrent-read-requests 32
:max-read-request-queue-size 1000})]
:max-read-request-queue-size 1000
:request-timeout 5000})]
(are [k v] (= v (.get options k))
TypedDriverOption/REQUEST_THROTTLER_CLASS
"ConcurrencyLimitingRequestThrottler"
Expand All @@ -44,7 +49,10 @@
32

TypedDriverOption/REQUEST_THROTTLER_MAX_QUEUE_SIZE
1000))))
1000

TypedDriverOption/REQUEST_TIMEOUT
(jt/millis 5000)))))


(deftest build-contact-points-test
Expand Down
3 changes: 2 additions & 1 deletion resources/blaze.edn
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@
:key-space #blaze/cfg ["DB_CASSANDRA_KEY_SPACE" string? "blaze"]
:put-consistency-level #blaze/cfg ["DB_CASSANDRA_PUT_CONSISTENCY_LEVEL" string? "TWO"]
:max-concurrent-requests #blaze/cfg ["DB_CASSANDRA_MAX_CONCURRENT_REQUESTS" nat-int? 1024]
:max-request-queue-size #blaze/cfg ["DB_CASSANDRA_MAX_REQUEST_QUEUE_SIZE" nat-int? 100000]}
:max-request-queue-size #blaze/cfg ["DB_CASSANDRA_MAX_REQUEST_QUEUE_SIZE" nat-int? 100000]
:request-timeout #blaze/cfg ["DB_CASSANDRA_REQUEST_TIMEOUT" pos-int? 2000]}

:blaze.db.resource-store.cassandra/duration-seconds {}

Expand Down

0 comments on commit 099d14c

Please sign in to comment.