GithubHelp home page GithubHelp logo

Comments (9)

xfeep avatar xfeep commented on May 26, 2024 1

Hi Andreas,
Thank you very much. You provided very useful information.
Now I can confirm that it will be a problem if we read body out of the sope of handler.invoke(req) because body will be closed at the end of handler.invoke(req).
So if your thread runs quickly before the end of handler.invoke(req) you can read the body successfully otherwise you will get an closed inputstream.
In the futerue version I will consider the tradeoff between resource leak risk and flexibility.

from nginx-clojure.

xfeep avatar xfeep commented on May 26, 2024

Hi, Filler.
Could you please tell us what value is bodyInputStream.getClass() when the bodyInputStream is missing?
There're three kinds of bodyInputStream. The first is FileInputStream when Nginx uses tmp body file. The second is NativeInputStream and the last is SequenceInputStream where stores a list of NativeInputStream.

from nginx-clojure.

afiller avatar afiller commented on May 26, 2024

Hi xfeep,
thank you for your reply and - by the way - for your great project. The library is so amazing and I love using it, it fills such an important gap by realising dynamic NGINX redirects.

I just tested it out and it's in both cases (contains body/misses body) a SequenceInputStream:

2023-08-17 09:59:00[warn][21190][pool-1-thread-1]>>>java.io.SequenceInputStream
2023-08-17 09:59:00[warn][21190][pool-1-thread-1]<<<<

2023-08-17 09:59:02[warn][21186][pool-1-thread-1]>>>java.io.SequenceInputStream
2023-08-17 09:59:02[warn][21186][pool-1-thread-1]<<<<{"event": {"event_timestamp_ms": 1692259142008, "product_id":....

Best regards,

Andreas

from nginx-clojure.

xfeep avatar xfeep commented on May 26, 2024

Hi, Andreas,
I'm glad to see this library is useful to you.
Please show the two values of bodyInputStream.available(). The first one is got at ExternalRESTCallHandler.invoke(request). The second one is got at InvocationHandler.run().
BTW I find thead pool mode is used (viz. jvm_workers > 0) and requst.hijack(..) / request,handler().hijack(..) is used together with thead pool mode. In most general cases requst.hijack(..) is used with plain mode to avoid blocking nginx.

from nginx-clojure.

afiller avatar afiller commented on May 26, 2024

Hi xfeep,

we never had problems with thread pool mode and NGINX and we are using this configuration quite long already. But I will keep an eye on it after your input.

The result is interesting:

In NOT successful cases the .available() is 401 and later 0.

In successful cases (so the content can also be read in run()) it is 1241 in both methods, so before starting the thread and inside the thread.

Summarized: When the stream is already at 1241 it is also possible to read it later. If it's not (401) it's empty later (0).

Hope it helps a bit in investigating. I keep my setup as it currently is for further testing.

from nginx-clojure.

afiller avatar afiller commented on May 26, 2024

PS:

We are not using "jvm_workers" (so the default of 0 should be used). The thread name comes from the thread pool executor I use in my class NginxJavaRingHandler for handling the parallel request:

Constructor:
ExecutorService executorService = Executors.newCachedThreadPool();

Usage:
// Run thread in thread pool executor
executorService.execute(new InvocationHandler(nginxRequest, channel));

...so this is simply internally in my class to be able to handle the hijacked requests in parallel.

from nginx-clojure.

xfeep avatar xfeep commented on May 26, 2024

PS: java.io.SequenceInputStream.available() only returns the first stream's available(). If there're serveral chunks in the body the value which available() returns is not always the total length of the body. So both .available() is 401 and .available() is 1241 are OK.

from nginx-clojure.

afiller avatar afiller commented on May 26, 2024

Thank you for your explanation and clarification. I adjusted my implementation now that it reads the body before going starting into the thread. The body will be handed over in the constructor of the same. It's less threaded in the end, but working stable. Thanks again!

from nginx-clojure.

xfeep avatar xfeep commented on May 26, 2024

@afiller Hi Andreas,

Please try a workaround way for better performance.

// get a user mananged body reference
Inputstream  umbody = (Inputstream)MiniConstants.BODY_FETCHER.fetch(nginxRequest.nativeRequest(), null);
// access umbody in another thread and then close it.
...

I've also created a related issue for the future enhancement about the hijack API.

from nginx-clojure.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.