Sorry for posting some clojure source code to demonstrate the situation.
explanations is below the source code.

-----------------------------------------------------------------------------------------
;; It will block here in request time but execute normally in main
(defn jwsgi-body [#^java.io.FileDescriptor input]
   (io! (with-open [rdr (reader (java.io.FileInputStream. input))]
          (reduce conj [] (line-seq rdr)))))

(defn run-jwsgi [app]
  (fn [hashtable]
    (jwsgi-resp (app (ring-req hashtable)))))

(defn jwsgi [hashtable]
  (let [pure-map (zipmap (.keySet hashtable) (.values hashtable))
        x (println "a")
        data (jwsgi-body (pure-map "jwsgi.input"))
        x (println "b")
        body (json/generate-string {:body data})
        pure-map (merge pure-map {"BODY" body "CONTENT_TYPE" "text/plain"
"CONTENT_LENGTH" (.length body) "SSL_CLIENT_CERT" nil "jwsgi.input" nil})]
    ((run-jwsgi app) pure-map)))

(defn -jwsgi [hashtable]
  (try (jwsgi hashtable)
    (catch java.lang.Throwable throwable
        (.printStackTrace throwable))
    (finally (println "Ready!"))))

;; main execute the logic normally
(defn -main [& args]
  (println "Hello! Galahad is serving for you!")
  (let [request (doto (new java.util.Hashtable)
                     (.put "jwsgi.input" (.getFD (java.io.FileInputStream.
"project.clj")))
                     (.put "REQUEST_METHOD" "GET")
                     (.put "SERVER_PORT" "8080")
                     (.put "PATH_INFO" "/recommend/question/user.json")
                     (.put "QUERY_STRING"
"data={%22ukey%22:%229x7vau%22,%22limit%22:20}")
                     (.put "HTTP_HOST" "localhost"))]
      (println (vec (-jwsgi request)))))
-----------------------------------------------------------------------------------------

Two situations for us:

  * situation A: jvm main method calling
  * situation B: jwsgi request-response calling

I found that:

  * the io operation in jwsgi-body function will blocked in situation B but
will execute normally in situation A
  * Othe io logic in our business code, which I did not show, take the same

I am guessing it is due to pthread mutex, but after search the source code,
I did not found anything useful.

Regards,
Mingli



On Sun, Jan 13, 2013 at 12:42 PM, Roberto De Ioris <[email protected]> wrote:

>
> > Hi, folks!
> >
> > A question about java and jwsgi!
> >
> > Right now I can start the jvm correctly,  but when I request on the jwsgi
> > method and the java code will retrieve other io resouces, and then the
> > execution blocked. But if the java code do not retrieve other io
> > resources,
> > the response is OK.
> >
> > I write same code for retrieving other io resouces in the main method, it
> > works. So I guess it is not a problem on jni calling.
> >
> > It seems that uwsgi disable the multi-threading functionality. While I
> > tried enable the *enable-threads* option for uwsgi, but still can not
> > work.
> >
> > Any advise?
> >
> >
>
> I am not sure to understand (it is a bit of time i do not look at jni),
> you mean that spawning java threads does not bring cpu back to the main
> thread ?
>
> Or you mean that spawning multiple threads (with --threads N) does not
> allow java requests to be served in parallel ?
>
>
> --
> Roberto De Ioris
> http://unbit.it
> _______________________________________________
> uWSGI mailing list
> [email protected]
> http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi
>
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to