pathom

:pathom: https://github.com/wilkerlucio/pathom/ & https://pathom3.wsscode.com & https://roamresearch.com/#/app/wsscode
tvaughan 2020-10-22T18:40:12.161Z

I have a parallel parser that is called in some http-kit middleware (for server-side rendering). This has been working for quite some time without issue, but just now broke when I added additional data to a test fixture. I think what's happening is that the database query takes just long enough now (despite being extremely quick) for http-kit to trigger some sort of timeout. This is pure speculation, but reducing the size of the test fixture and switching to a normal parser both solve the problem. Does this ring a bell for anyone? What am I doing wrong? Below is what I had. drawings-endpoint is the function called in the http-kit middleware.

(defonce ^:private drawings-parser
  (pathom/parallel-parser
    {::pathom/env {::pathom/reader [pathom/map-reader
                                    pathom-connect/parallel-reader
                                    pathom-connect/open-ident-reader
                                    pathom-connect/index-reader]
                   ::pathom/process-error ex-handler
                   ::pathom-connect/mutation-join-globals [:tempids]}
     ::pathom/mutate pathom-connect/mutate-async
     ::pathom/plugins [(pathom-connect/connect-plugin {::pathom-connect/register drawings-handlers})
                       pathom/error-handler-plugin
                       pathom/trace-plugin]}))

(defn drawings-endpoint
  ([query]
   (drawings-endpoint query {}))
  ([query opts]
   (when query
     (<!! (drawings-parser opts query)))))
And this my "solution"
(defonce ^:private drawings-parser
-  (pathom/parallel-parser
+  (pathom/parser
     {::pathom/env {::pathom/reader [pathom/map-reader
-                                    pathom-connect/parallel-reader
+                                    pathom-connect/reader2
                                     pathom-connect/open-ident-reader
                                     pathom-connect/index-reader]
                    ::pathom/process-error ex-handler
                    ::pathom-connect/mutation-join-globals [:tempids]}
-     ::pathom/mutate pathom-connect/mutate-async
+     ::pathom/mutate pathom-connect/mutate
      ::pathom/plugins [(pathom-connect/connect-plugin {::pathom-connect/register drawings-handlers})
                        pathom/error-handler-plugin
                        pathom/trace-plugin]}))
@@ -32,6 +32,7 @@
   ([query opts]
    (when query
-     (<!! (drawings-parser opts query)))))
+     (drawings-parser opts query))))
 

souenzzo 2020-10-22T19:10:18.163200Z

@tvaughan looks like that you are doing Locking IO inside parallel-parsers resolvers You can solve it by using a thread-pool or use a non-blocking db api that probablly will have a internal thread-pool In real, looks like that your use-case a simple "serial" parser will be a better solution

tvaughan 2020-10-22T19:12:04.165200Z

The db query is a simple datomic pull-syntax read operation

souenzzo 2020-10-22T19:12:57.166600Z

If you are using #datomic cloud I highly recommend use p/parser I started with a parallel-parser, and after A LOT of debbuging, thread pool, and others patterns/tweaks, to make datomic.client.(async).api work with parallel-parser, I see that p/parser is more performatic 😞

tvaughan 2020-10-22T19:13:01.166800Z

I switched to the parallel parser because it seemed like (somewhat unconfirmed) that using the serial parser would block all other pending requests

tvaughan 2020-10-22T19:14:16.167900Z

> I see that `p/parser` is more performatic Interesting. I came to the opposite conclusion

tvaughan 2020-10-22T19:14:31.168200Z

Thanks @souenzzo I'll stick with the serial parser

tvaughan 2020-10-22T19:23:33.169700Z

Currently on-prem, but cloud eventually

wilkerlucio 2020-10-22T19:24:29.171500Z

@tvaughan serial parser is better for most users, parallel parser is way too complex and adds a ton of overhead, to cross the "overhead gap" you must have quite large queries (and I mean 300+ attributes in a single query) and resolvers that have IO that is easy to distribute (for example hitting many different services)

1
wilkerlucio 2020-10-22T19:24:53.172300Z

the serial is not going to prevent many requests at once, the serial means that for one EQL query, that query is processed sequentially (one attribute at a time)

wilkerlucio 2020-10-22T19:25:09.173Z

while the parallel can parallelize differnet attributes on the same query

wilkerlucio 2020-10-22T19:26:41.175300Z

but I can undestand the confusion, for a time I used to recommand the parallel as the starter, but time goes on and we learn better 🙂

tvaughan 2020-10-22T19:27:37.176200Z

To be clear, the parser in question is used both for server side rendering and as an api endpoint. The performance characteristics I mention are related to its use as an api endpoint. The problem I mention above shows up when used in http-kit middelware. I was surprised that parallel requests to http-kit would block. However, I'm not so surprised that using a parallel reader in http-kit middeware is a problem

tvaughan 2020-10-22T19:28:44.176800Z

Cool. Thanks for the clarification @wilkerlucio. That does clarify its purpose for me

tvaughan 2020-10-22T19:30:31.177700Z

> for a time I used to recommand the parallel as the starter, First I went back to the documentation. FYI - https://blog.wsscode.com/pathom/v2/pathom/2.2.0/core/async.html says: > Nowadays the parallel parser is the recommended one to use ...

wilkerlucio 2020-10-22T19:31:07.177800Z

thanks, bad old docs, going to update this now 🙂

👍 1
tvaughan 2020-10-22T19:34:12.178300Z

Cool. Thanks for this

nivekuil 2020-10-22T19:44:56.178500Z

since pathom3 will only have reader3, how will async resolvers work? You can't return core.async channels from resolvers/mutations anymore right?

wilkerlucio 2020-10-22T19:54:22.178700Z

thank you for the nudge! https://github.com/wilkerlucio/pathom/commit/9827d1dd671cfbd9ed7521a7ca3f29de7e00ed5c

dehli 2020-10-22T19:54:55.179Z

I’m using reader3 with core.async channels and it’s working for me

wilkerlucio 2020-10-22T19:56:27.179200Z

rest assured that Pathom 3 will support async 🙂 in Pathom 2 reader3 supports sync and async. When I say pathom 3 will only have reader3, is more of a way to say the type of processing it will do, because Pathom 3 will not have readers at all (neither parsers).

tvaughan 2020-10-22T20:02:45.179400Z

That's super helpful. Thanks!

nivekuil 2020-10-22T20:06:10.179600Z

In reply to @￱￱slack￱￱￱￱￱￱t03￱￱r￱￱z￱￱g￱￱p￱￱f￱￱r=2d￱￱u2￱￱u78￱￱h￱￱t5￱_￱g:nivekuil.comI’m using reader3 with core.async channels and it’s working for meah, it does -- I thought you had to use the parallel reader alongside the parallel parser/mutate. I guess that confusion can't happen in pathom3 if it's not even a thing anymore :)

nivekuil 2020-10-22T20:29:58.179800Z

so just changing from parallel-reader to reader3, still using parallel-parser, seems to cause a few random attributes (like 1% of the stuff returned from a big query) that my fulcro app previously loaded fine to be nil. Is this expected?

wilkerlucio 2020-10-22T20:42:38.179900Z

reader3 is experimental, so errors are expected yes