Git Product home page Git Product logo

wolfram-server's Introduction

wolfram-server

JSON based Wolfram Language expression evaluation server

Usage notes

The server accepts HTTP POST requests, where the body data consists of Wolfram Language code. It takes this code, as a string, and evaluates it. Finally it converts the evaluated expression to ExpressionJSON and sends this JSON expression back to the client making the request.

Starting the Wolfram Language server

General usage:

wolframserver.wls [port]

If port is omitted a random (available) port is automatically selected.

Example, launch the server on port 5858:

wolframserver.wls 5858

Connecting to the server

Examples of language specific clients are in the clients directory.

Using curl
> curl -d "DateString[]" -X POST http://127.0.0.1:5858
"'Fri 26 Jul 2019 14:33:28'"
Using wget
> wget -qO- --post-data="DateString[]" http://127.0.0.1:5858
"'Fri 26 Jul 2019 14:25:56'"
Using Wolfram Language
> wolfram-client.wls "DateString[]"
"'Fri 26 Jul 2019 14:45:41'"
Using Go

Directly:

> go run go-client.go "DateString[]"
URL:> http://127.0.0.1:5858
response Status: 200 OK
response Headers: map[Content-Type:[application/json]]
response Body: "'Fri 26 Jul 2019 14:32:25'"

With compilation:

> go build go-client.go
> go-client.exe "DateString[]"
URL:> http://127.0.0.1:5858
response Status: 200 OK
response Headers: map[Content-Type:[application/json]]
response Body: "'Fri 26 Jul 2019 14:31:41'"

Using Python
> python-client.py "DateString[]"
result: "'Fri 26 Jul 2019 14:30:43'"

Using R

library(httr)
r <- POST('http://127.0.0.1:5858', body = 'DateString[]' )
print(content(r))
Using NodeJS
> node node-client.js "DateString[]"
statusCode: 200
"'Fri 26 Jul 2019 14:31:09'"
Using Windows PowerShell
> (Invoke-WebRequest -Method POST -Body "DateString[]" -Uri http://127.0.0.1:5858).Content
"'Fri 26 Jul 2019 14:36:47'"

wolfram-server's People

Contributors

arnoudbuzing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

wolfram-server's Issues

Request for clarification

Hi there, I was able to make use of this script for a very specific requirement of communicating from nodejs. Very well written piece of code and useful as well. Many thanks.
An expanded requirement for our specific scenario is to have this wolfram server as a state machine wherein for example the output of the first command in the sequence given from nodejs is available for processing the second command in the sequence. Is this possible to be implemented in the server?

Parallelizing multiple servers

Hello,

very useful project, thanks.

So I have a question, I am not sure how to contact you, and maybe others could be interested so I'll write this here.

I have a use case where I run this Wolfram server code on my local machine inside a notebook, and it receives requests from a Python script, it works fine, this is great. This is part of a bigger pipeline however, and the calculation I make inside my Wolfram notebook is a big bottleneck in terms of execution time.

For this reason, I'm trying to run multiple server instances simultaneously, to "load balance" the incoming requests flux. The idea is to do this by duplicating the notebook and changing the port I listen to on each notebook.

I can currently achieve this by starting each version of the notebook on a separate instance of the Mathematica software, but by doing that, I have to use several Mathematica licenses, which severely limits the number of servers I can launch (I don't want to use too big of a proportion of the license pool available in my company).

When I'm trying to do this by using a single Mathematica instance, by just opening all the notebooks on this instance and running them, only the first one I start is effective and actually listens on the requested port, the following ones don't.

My question then is: do you see an effective way of running multiple instance of this Wolfram server code without using multiple Mathematica licenses? I'm not trying to circumvent the licensing system, I just feel like it should be possible and I am doing it wrong.

Many thanks.

ZeroMQLink error

I'm using version 12.3 of wolframscript and when I try to run the server script I get the following error:
Argument ZeroMQLinkPrivate$AsyncState[Task] is not a valid AsynchronousTask object

I'm not an expert with connection functions but if I just copy paste the script and run it in a REPL and ignore the last couple of lines about ZeroMQ and Async I can use a client. What exactly is the purpose of this last bit?

CPU Usage

On Debian 9 and Mathematica 11.3, idle CPU usage around 6%. I replaced the TaskWait with a Dialog[] to keep it alive and CPU usage dropped to 1%

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.