After searching for a way to run Java code from a Django (python) application, I found out that Py4J is the best option for me. I tried the Jython, JPype, and Python subprocess, and each one has certain limitations:
- Jython My application runs in python.
- JPype is wrong. You can start the JVM only once, after which it cannot start again.
- Python subprocess. It is not possible to pass a Java object between Python and Java due to a regular console call.
On the Py4J website it says:
In terms of performance, Py4J has more overhead than previous solutions (Jython and JPype) because it relies on sockets, but if performance is critical to your application, accessing Java objects from Python programs may not be the best idea.
In my application performance, it is very important because I work with the Mahout Machine Learning Framework. My question is: will Mahut run slower due to the Py4J gateway server, or does this overhead mean that calling Java methods from Python functions is slower (in the latter case, Mahout performance will not be a problem, and I can use Py4J).
source share