Re: SWI-Prolog engine as a Service
Jeff Rosenwald <[email protected]> Thu, 24 Apr 2014 09:20:25 -0400 (EDT)
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
All: There is perhaps another option. You can serialize your JAVA objects into byte streams using Google's Protocol Buffers library. You pass the byte stream to your SWIPL as service via a socket stream. SWIPL's protobufs library can then parse the byte stream into an appropriate term. You do whatever with that term. You then take your answer and serialize it into a byte stream that you write back to the socket stream. Your JAVA program (via protobufs) parses it back into a JAVA object instance, and you do whatever with that. Once you figure our how Protobufs work on the JAVA side, it's not hard to set up on the SWIPL side. It is without a doubt, simpler and faster than using a web server and avoids most all of the aforementioned complications. See: http://www.swi-prolog.org/pldoc/package/protobufs.html Regards, Jeff R. -----Original Message----- From: Jan Wielemaker <[email protected]> To: Sergio Castro <[email protected]>; Pavan Kumar <[email protected]>; swi-prolog <[email protected]> Sent: Wed, Apr 23, 2014 3:09 am Subject: Re: [SWIPL] SWI-Prolog engine as a Service Pavan, Sergio, On 04/22/2014 11:56 PM, Sergio Castro wrote: > If your client is a Java program and you can execute it in the same > machine than SWI, I think the best you can do is to try with JPL. > Configuring it as a web service in that scenario may add another > layer of complexity. Also you would experiment a strong impact on > performance. Yes and no. As you have experienced, JPL is not without problems. On Unix systems Prolog tends to fight over signals with Java (both needs signals for similar thread communication requirements), causing several stability problems depending on what you are doing and which JVM you are using. These problems are very hard to diagnose and it is unclear whether or not they can be fixed. Certainly not in a proper JVM-independent way. On all platform, merging Prolog and Java suffers from configuration issues. Most have to do with wrong paths and merging different architectures (e.g., 32 and 64-bit). They require proper knowledge of dynamic linking and dynamic linking debugging tools to fix. It is hard to provide recipes because there are just too many combinations of OS, Prolog and JVM. Using Prolog as a (web-) service, talking through sockets avoids all this. You get socket communication overhead in return. If you use direct sockets, that should be well below 1ms. If you use HTTP it becomes easier, be the price you pay is `a few ms'. The other advantage is that you have natural access to the Prolog toplevel, which makes it easier to debug your program. I don't see the problem of `starting Prolog as a service': just start Prolog and use the http HOWTO/Tutorial to provide the service. You can start Prolog by hand separately, or make the Java program fire Prolog. Cheers --- Jan > > Sergio > > > Le Mardi 22 avril 2014 17h26, Pavan Kumar <[email protected]> a écrit : > > I have a Java Program that will generate a Query for SWI-Prolog(CLPFD). I >> need this query to be sent to SWI-Prolog for further processing and getting >> back the results or Output of the SWI-Prolog. >> >> I figured out JPL is a good approach and also we can try to host SWI-Prolog >> engine as a Web Service and send our query which is generated by Java >> Program to get back the results. >> >> I saw a web services section in SWI-Prolog Documentation but it seems like >> creating web Servers in SWI-Prolog which serves html pages and http >> requests but not the SWI-Prolog Functionality as a Service itself. >> >> Can you let me know which is the better approach for my problem? JPL or >> Hosting SWI-Prolog engine as a service? >> >> If the latter is better can you guide me how to do it and communicate with >> the web service? >> >> I am using a Windows 8 machine with SWI-Prolog 6.6.4 setup. >> >> Thanks, >> Pavan. >> -------------- next part -------------- >> HTML attachment scrubbed and removed >> _______________________________________________ >> SWI-Prolog mailing list >> [email protected] >> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog >> >> >> > -------------- next part -------------- > HTML attachment scrubbed and removed > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > _______________________________________________ SWI-Prolog mailing list [email protected] https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog -------------- next part -------------- HTML attachment scrubbed and removed _______________________________________________ SWI-Prolog mailing list [email protected] https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog