This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-06-26
Channels
- # aws (1)
- # beginners (50)
- # boot (32)
- # chestnut (2)
- # cider (14)
- # clara (23)
- # cljs-dev (131)
- # cljsrn (44)
- # clojure (133)
- # clojure-belgium (3)
- # clojure-denmark (4)
- # clojure-dev (6)
- # clojure-italy (4)
- # clojure-nl (2)
- # clojure-russia (95)
- # clojure-spec (59)
- # clojure-uk (14)
- # clojurescript (157)
- # cursive (26)
- # data-science (1)
- # datomic (160)
- # devops (5)
- # dirac (80)
- # emacs (2)
- # graphql (2)
- # jobs (2)
- # lein-figwheel (1)
- # lumo (9)
- # off-topic (151)
- # onyx (2)
- # parinfer (2)
- # pedestal (5)
- # perun (2)
- # re-frame (60)
- # reagent (3)
- # remote-jobs (1)
- # test-check (3)
- # uncomplicate (11)
- # yada (1)
Does anyone know how to store state in one instance of a simulation in clj-gatling
?
/edit Answer from the docs:
http://i.imgur.com/SISAxzT.png
Hmm looks like the context
is passed along in every step. Hopefully I can just assoc.
That’s not it. assoc
ing to that context is not persistent
over steps
One solution is to keep a separate database, but it is not very clean
Aaah you can send the context forward
Return [result context]
Next question: in clj-gatling
my response times are way longer than they actually are. It seems like it is not only counting the time my request takes, but also the time it takes to run on my computer. Is there a way to fix this?
When I time the request
(defn login-request [ctx]
(go
(time (let [{:keys [status] :as res} @(http/get ""
{:headers {"Accept" "text/html"}})]
[(= status 200) (assoc ctx :state "state")]))))
It prints “Elapsed time: 200ms”.
But the end result in the Gatling reports states it lasts longer than 1200ms.Well spotted
If I don’t wrap it in a go-block the same problem occurs
I think if I use
(defn- http-get [url _]
(let [response (chan)
check-status (fn [{:keys [status]}]
(go (>! response (= 200 status))))]
(http/get (str base-url url) {} check-status)
response))
like in the example things will work.https://github.com/mhjort/clj-gatling-example/blob/master/src/clj_gatling_example/simulations.clj
Okay not using a go block works!
This works:
(defn login-request [ctx]
(let [check-result (fn [{:keys [status]}] (= status 200))]
(http/get ""
{:headers {"Accept" "text/html"}}
check-result)))
No problem 🙂
Up to 4000 usersHow can I refer to a var inside ns1 when the macro defined in ns1 is called from ns2?
(ns ns1)
(defn a-fn* [] "hello")
(defmacro a-marco []
`(defn a-fn [] (a-fn*)))
(ns ns2)
(ns1/a-marco) ;=> Can't refer to qualified var that doesn't exist
I don't believe you see that error message on a fresh repl, you must have some stale state
also that macro is slightly wrong, should be
(defmacro a-macro [] `(defn ~'a-fn [] (a-fn*)))
I'm playing with an event sourcing/CQRS style system in Clojure. It involves some number of load-balanced app servers. My idea is to have local in-memory caches, and then "catch up" by applying pending events before any read operations.
I'm trying to avoid having any extra pieces like a message queue
does that seem sane?
generally, macros that inject global names into a namespace are not idiomatic in clojure
a slightly better version would be e.g.
(defmacro a-macro [name] `(defn ~name [] (a-fn*)))
but still, this doesn't look like a very useful macrothey have their uses, probably finding out what is the goal is a step to take before judging something as not idiomatic
why would you intern a var in a namespace that just delegates to a var in another? just refer that one directly
delegating is part of if, passing some variables, but not all is the other half (something like partial, but on macro level)
I couldn't use partial
because what's passed might be an atom that needs to be derefed later.
Needless to say my example was stripped down to the bare minimum to illustrate the problem I was having. 🙂
Wondering what people do for translations in their application? The key based stuff puts me off (https://translation.io/blog/gettext-is-better-than-rails-i18n), and I'd like to use industry-accepted systems (PO, XLIFF, MessageFormat). Doing this for cljs & clj.
How can I extend a type, like java.util.HashMap
to support conj
. Which is the protocol for that?
here's how it was done in the priority-map https://github.com/clojure/data.priority-map/blob/master/src/main/clojure/clojure/data/priority_map.clj#L255
right, you can do that if you're in control of new types but it's simply not possible to retrofit on existing types like java.util.HashMap
(and even it it could be possible, conj
is defined as an operation on persistent colls, so on mutable ones it would be breaking its contract)
okay, so If I want to wrap something, for example Array[ResultSet]
to vector of map. I can't just extend-type, I should iterate it.
@doglooksgood you could define a multimethod which is identity for vector of hashmap, but uses into
to populate clojure datatypes if it gets arrays and java.util.HashMap
(let [a (try (java.io.FileInputStream. keyObjectFile) (catch Exception e (println (str "1caught exception: " (.getMessage e)))))] (println a) (try (.load keystore a) (catch Exception e (println (str "2caught exception: " (.getMessage e))))))
but I am getting: java.io.FileInputStream cannot be cast to java.security.KeyStore$LoadStoreParameter
(defn load-key-store [keystore-filename keystore-password]
(with-open [is ( keystore-filename)]
(doto (java.security.KeyStore/getInstance "JKS")
(.load is (.toCharArray keystore-password)))))
works great 👍
check the javadoc of java.security.KeyStore/getInstance
maybe there’s a method that doesn’t need a password?
the password can be null i.e. nil
(defn load-key-store [keystore-filename]
(with-open [is ( keystore-filename)]
(doto (java.security.KeyStore/getInstance "JKS")
(.load nil))))
or you could use the defn
from above and just call (load-key-store filename nil)
then you won't have to change it when you do have a password on the keystore
mmm now I have a problem when I put in the jetty configuration the Keystore object it send me this error in the browser
BTW I would strong recommend against doing SSL termination in Jetty
it's much better to do it with a reverse-proxying load balancer
e.g. NGINX or an ELB in AWS
you can do SSL termination in Jetty just fine but it just doesn't seem worth the effort when other tools do it better
if you really really really need one host to serve up HTTPS from a single Java process, then sure
otherwise you're probably already deploying your app behind something that can do SSL termination
or you should be
sorry, #off-topic and uninvited advice
but if you're developing a web app in Clojure, trying to set up SSL in Jetty is probably pretty orthogonal to the real problems you're trying to solve
maybe there are other complex things which are not supported or they are better with other server!
it's more about not doing it
when you don't have to
So what resources exist for learning deployment? My app is Clojurescript with a Clojure REST api, I have a dedicated "server dude" but I don't know that he'll know what to do with me. I'm assuming for Clojurescript I'd just NGINX-up the html and js file that makes the app go round, and for clojure I guess I could just run my Compojure rest api, but that leaves the question of how tf do I load balance that and etc. I have a ton of questions about this, so if anyone has a clojure/script deployment bible, smack me with it
@alice I think the answer is “the same way you’d do any JS / JVM combination web app” really — load balancing etc, and most of the deployment considerations, aren’t Clojure-specific. I know that doesn’t help but…
@alice your Compojure rest API should be able to serve the HTML and compiled cljs
I can tell you what we do at World Singles: we host the HTML and JS on S3 and serve that up through Amazon (using their CDN, DNS, etc) and the Clojure code gets wrapped up as uber JAR files and deployed to a bunch of servers and spun up with java -jar
via scripts/services, and proxied via Apache, and F5 load balancers etc.
We have a separate deployment chain for front and back end components — since they are actively developed on different schedules, by different teams.
ah, my client/server (i.e. cljs/clj) code is all in one uberjar
@jcromartie some of us don't have the same kinda foresight lmao
every project starts out fresh and beautiful, and then reality hits
At least it's not a Clojure uberjar that starts up Jetty with an embedded JRuby on Rails and Spring web app loaded from precompiled WAR files.
where the Rails app calls the legacy Spring app to provide a REST API 🙂
and the Clojure code is creating DAO objects to be loaded by the Spring app via dependency injection
all in one process!
That sounds terrifyingly specific.
I mean, just a hunch, but I think a project like that would be pretty crazy.
it would be even worse if the Spring app only communicated via SOAP
now i’m super curious to know explicitly if you’ve had to work on such a thing and how it came to be
you should be
I can make up more totally hypothetical aspects too
like if you couldn't instantiate classes like (Foo.) but instead had to look them up by name every time, and the bulk of the code was interop requiring lots of this sort of thing
or static method invocations
without being able to do (Foo/bar)
that would be silly
in such a case, it would also be helpful to know how to get a Java enum value without being able to reference classes directly
(.invoke (.getMethod (get-class system class-name) "valueOf" (into-array Class [String])) nil (into-array String [value]))
for reference, just in case I or anybody else ever need that 🙂
classloader problems suck
is there any kind of string function that works with named parameters in a map? like python's string formatting (3+)?
that’s close to how selmer does templates https://github.com/yogthos/Selmer
Selmer is kind of like that https://github.com/yogthos/Selmer
maybe we should call it juxt
lol, nobody is gonna be cool with me pulling in a whole template rendering library for the string parser
I wonder if something similar could be hiding deep in clojure.pprint/cl-format
I should probably just use format and not be a lazy person. I dont have a special use case, I just margianlly prefer the syntax
insane stuff
we just released the library we wrote for AWS Step Functions, in case anyone’s interested: https://github.com/uwcpdx/stepwise
tjtolton, it's pretty easy to write that if you (or a dependency) is already including instaparse or cljr-antlr (check lein deps :tree
). See this for a minimal example: https://github.com/philipsdoctor/DST