Package: gabriel-server
Gabriel Server LibraryInstallationRequires Python 3.6 or newer.Runpip install gabriel-serverUsageData is processed by Cognitive Engines. Each cognitive engine is implemented in
a separate class that inheritscognitive_engine.Engine. Thehandlemethod is
called each time there is a new frame for the engine to process.handlegets
passed anInputFrame.
It must return aResultWrapper.
Thehandlemethod should create aResultWrapperusing thecognitive_engine.create_result_wrapperfunction. Thehandlemethod can add
results to thisResultWrapper, or just return theResultWrapperinstance it
gets fromcreate_result_wrapperwithout adding results (if the client does not
expect results back). The client will get a token back as soon ashandlereturns aResultWrapper(even if theResultWrapperinstance just came fromcreate_result_wrapperand nothing else wass added to it). Therefore, returning
fromhandlebefore the engine is ready for the next frame will cause the
engine to get saturated with requests faster than they can be processed.Single Engine WorkflowsThe simplest possible setup involves a single cognitive engine. In this case,
the Gabriel Server and the cognitive engine are run in the same Python program.
Start the engine and server as follows:local_engine.run(engine_factory=lambda:MyEngine(),source_name='my_source',input_queue_maxsize=60,port=9099,num_tokens=2)engine_factoryshould be a function that runs the constructor for the
cognitive engine. A separate process gets created with Python'smultiprocessingmodule, andengine_factorygets executed in this process.
Havingengine_factoryreturn a reference to an object that was created beforelocal_engine.runwas called is not recommended.Multiple Engine WorkflowsWhen a workflow requires more than one cognitive engine, the Gabriel server must
be run as a standalone Python program. Each cognitive engine is run as an
additional separate Python program. The cognitive engines can be run on the same
computer that the Gabriel server is running on, or a different computer. Under
the hood, the server communicates with the cognitive engines usingZeroMQ.The Gabriel server is run usingnetwork_engine.server_runneras follows:server_runner.run(websocket_port=9099,zmq_address='tcp://*:5555',num_tokens=2,input_queue_maxsize=60)Cognitive engines are run usingnetwork_engine.engine_runneras follows:engine_runner.run(engine=MyEngine(),source_name='my_source',server_address='tcp://localhost:5555',all_responses_required=True)Note thatengineshould be a reference to an existing engine, not a function
that runs the constructor for the engine. Unlikelocal_engine,network_engine.engine_runnerdoes not run the engine in a separate process.Whenall_responses_requiredis False, the client will not receive a result
from this engine, if a different engine processing the same frame already
returned a result for this frame. Whenall_responses_requiredis True,
the server will send every result this engine returns. Typically, you should setall_responses_requiredto True when an engine returns results to the clients,
and False when an engine stores results but does not include anything useful for
the client in theResultWrapperinstance that it returns.The server should be started before the engine runner.TimeoutsWhen setting timeout values, consider the following fromZeroMQ's guide:If we use a TCP connection that stays silent for a long while, it will, in
some networks, just die. Sending something (technically, a "keep-alive" more
than a heartbeat), will keep the network alive.server_runner.runtakes an optionaltimeoutargument. The default value of
five seconds should be sufficient unless one of your cognitive engines might
take more than five seconds to process a frame. Thistimeoutvalue
should be set to the longest amount of time that any of your cognitive engines
could take to process a frame. The engine runner will not send or reply to
messages while the cognitive engine is in the middle of processing a frame.engine_runner.runtakes optionaltimeoutandrequest_retriesparameters.request_retriesspecifies the number of attempts that this runner will make to
re-establish a lost connection with the Gabriel server. The number of retry
attempts do not get replenished at any point during the engine runner's
execution. The defaulttimeoutandrequest_retriesvalues should be
sufficient for most configurations.Publishing Changes to PyPiUpdate the version number in setup.py. Then followthese instructions.