Nginx-Clojure Module Release 0.1.0--Let Nginx embrace Clojure & Java

Hi!

Nginx-Clojure Module Release 0.1.0 was out several day ago!

It is a module for embedding Clojure or Java programs, typically those
Ring
based handlers.

It is an open source project hosted on Github, the site url is
https://github.com/xfeep/nginx-clojure

With it we can develope high performance Clojure/Java Web App on Nginx
without any Java web server.

By the way the result of simple performance test with Nginx-Clojure is
inspiring, more details can be got from

https://github.com/ptaoussanis/clojure-web-server-benchmarks

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,246437,246437#msg-246437

May be somebody wonder what the differences between Nginx UWsig Module
and
Nginx Clojure Module when integrating JVM.

They are quite different. Nginx Clojure Module embed JVM instance into
the
Nginx Worker and they are in the same process and have the same memory
address space.

There 's no IPC cost when using Nginx Clojure Module and even no thread
swith cost by the default way.

Nginx UWsig Module can not avoid IPC cost or posix standard socket cost
because Nginx Worker and the JVM process
are different Process when using Nginx UWsig Module.

Please correct me if there 's any mistake.

xfeep Wrote:

With it we can develope high performance Clojure/Java Web App on Nginx
without any Java web server.

By the way the result of simple performance test with Nginx-Clojure is
inspiring, more details can be got from

https://github.com/ptaoussanis/clojure-web-server-benchmarks

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,246437,246456#msg-246456

With the default setting pipe is not used.

Pipe is only used for enable jvm thread pool mode only when jvm_workers

0
(jvm_workers default = 0).

Further more pipe is never used to transfer the while request or
response
message.
When under jvm thread pool mode, pipe is only used to transfer a event
flag
(only one pointer size)。

ONLY IF you cann’t resolve your performance problems by increasing
worker_processes or reducing single request-response time, you can
consider
the way of setting jvm_workers > 0 which is not encouraged.

Thread switch cost means Thread context switch cost.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,246437,246458#msg-246458

May be somebody wonder what the differences between Nginx UWsig Module
and
Nginx Clojure Module when integrating JVM.

They are quite different. Nginx Clojure Module embed JVM instance into the
Nginx Worker and they are in the same process and have the same memory
address space.

There 's no IPC cost when using Nginx Clojure Module and even no thread
swith cost by the default way.

Are you sure about it ? i see your code transfer requests data using a
pipe (that is a very good approach indeed as avoid you to introduce
blocking parts in nginx)

What you mean for “thread switch cost” ?


Roberto De Ioris
http://unbit.it

(only one pointer size)。

ONLY IF you cann’t resolve your performance problems by increasing
worker_processes or reducing single request-response time, you can
consider
the way of setting jvm_workers > 0 which is not encouraged.

Thread switch cost means Thread context switch cost.

Sorry, but are you saying that your suggested usage for concurrency is
multiprocessing ?

Multiprocessing is completely alien in the jvm (the vm is not even
fork-friendly) and that would mean the nginx worker completly give
control
to the jvm and this is something bad as the jvm is a blocking vm.

The jvm world is thread-centric (and trust me, i needed to deal with
dozens of different threading implementations for uWSGI and the jvm is
the
best one) so i am quite doubtful saying “multiprocess by default” would
be
a successfull approach (well the amount of memory per-app will be huge)


Roberto De Ioris
http://unbit.it

roberto Wrote:

dozens of different threading implementations for uWSGI and the jvm is


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

One Nginx worker , typically single thread, can handle thousands of
request
by non-blocking events. So we need less Nginx workers than the threads
in a
typical java server.

Java thread is not lightweight and uses more memory than general
thread.

I don’t think JVM is blocking vm. In my eye JVM just a executor of java
class. By JNI we can any no-blocking things just as a general Nginx
modula
written by c.

With the default mode in Nginx-Clojure 0.1.0 there 's one jvm instance
embed
per Nginx worker. The will be some no-blocking api provided by the next
version of Nginx-Clojure.

With Nginx-Clojure 0.1.0 you can also use one JVM instance with a thread
pool if you like, just set nginx worker processes = 1 and set
jvm_workers =
the number of java threads you will use.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,246437,246469#msg-246469

Thanks for your good hints.

I see there 's a good no-blocking mysql client Libdrizzle from
https://launchpad.net/drizzle.

With Nginx-lua or Openresty , Libdrizzle has been used in production.

I won’t hope every thing is no-blocking and I think it is unnecessary.

Only when blocking hurt us we have to conside using no-blocking
methods.

For design of no-blocking api we can only use a simple callback pattern,
let
user to determine whether use threads or not.

Even in Nginx-Clojure 0.1.0, developers can also use his owner thread or
thread pool.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,246437,246473#msg-246473

Roberto De Ioris
a
typical java server.

yes, for sure, the problem is that you need to integrate the whole jvm
part with the nginx event loop, you cannot use other ways (unless you
introduce back threads)

This is what i told you in the clojure list: invest on implementing the
nginx api as jni, otherwise all will remain a proof of concept.

Just as an example, how do you plan to integrate with mysql in a
non-blocking way ? you need a mysql adapter that will use the nginx api
and so on… (huge work honestly)

and yes, until you do not manage to integrate the nginx api in jni, the
jvm is a blocking part for nginx :slight_smile:

I hate to bore you expecially because you are pushing a new technology
and
the last thing you need is losing entusiasm or being blasted, but the
world is already full of people doing non-blocking programming in the
wrong way :slight_smile:


Roberto De Ioris
http://unbit.it

Thanks for your good hints.

I see there 's a good no-blocking mysql client Libdrizzle from
https://launchpad.net/drizzle.

With Nginx-lua or Openresty , Libdrizzle has been used in production.

yes, both can be of great inspiration for you/your project

I won’t hope every thing is no-blocking and I think it is unnecessary.

unfortunataley (well, today is the second time i say thins thing :wink: if
you
are developing in a non-blocking environment, all must be non-blocking
without exceptions


Roberto De Ioris
http://unbit.it

Thanks a lot!

So far about the nginx-clojure project the most valuable adviceI have
received is from you!

Best regards!

roberto Wrote:

Roberto De Ioris
http://unbit.it


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,246437,246480#msg-246480

Hi reberto,

Nginx Clojure Module V0.2.0 provides three choices for handling blocked
I/O
with Java/Clojure Now.

(1) Coroutine based Socket
It’s Non-blocking Java Socket API Compatible and work well with
largely
existing java library such as apache http client, mysql jdbc drivers
etc.
non-blocking, cheap, fast and let one java main thread be able to handle
thousands of connections.
(2) Asynchronous Socket
(3) Thread Pool

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,246437,249651#msg-249651

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs