All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog.
IterableQueue.put
gets keyword argtimeout
.IterableQueue.get
becomes_get
.- New functions
mpservice.streamer.{fifo_stream, async_fifo_stream}
. - Simplified implementations of classes
mpservice._streamer.*Parmapper*
and methodsmpservice.mpserver.{Server, AsyncServer}.stream
using these functions. mpservice.streamer.Stream.parmapper
parameternum_workers
was renamedconcurrency
because the meaning of the latter is more correct in async contexts.mpservice.mpserver.Server.stream
andmpservice.mpserver.AsyncServer.stream
lost parameterto_stop
.
- Bug fix in
IterableQueue
when using a multiprocessing SimpleQueue. - Refinements and enhancements to
IterableQueue
. mpservice.mpserver.{Server, AsyncServer}.stream
gets a new parameterpreprocess
.- New classes
ProcessRunner
andProcessRunnee
inmpservice._streamer
.
- Added new class
mpservice.streamer.IterableQueue
. - The directory structure under
mpservice.multiprocessing
better mirrors that of the standard lib. Parmapper
andServer.stream
get new parameterto_stop
to allow the stream to be stopped by external forces.
- Finetune
mpservice.multiprocessing.SpawnProcess
regarding termination, background threads, and error handling. mpservice.multiprocessing.Queue
gets propertymaxsize
, making it aligned withqueue.Queue
, which has attributemaxsize
.
- Finetune
mpservice.multiprocessing.server_process
:- support pickling of
ServerProcess
objects. - buf fix regarding custom authkey to
ServerProcess
- support pickling of
- Minor improvement to
mpservice.multiprocessing.server_process
. - Upgraded
uvicorn
to 0.30.0; revisedmpservice._http
accordingly.
- Refactored and enhanced
mpservice.multiprocessing.server_process
.
mpservice.multiprocessing.server_process.ServerProcess
enhancement: if a proxy function raises exception in the server process, ampservice.multiprocessing.remote_exception.RemoteException
is returned to the request and then raised to the user, hence the user (outside of the server process) gets more useful traceback info.mpservice.multiprocessing.server_process
is heavily refactored for enhancements and simplifications.
mpservice.mpserver.Worker
gets new methodstream
for some special use cases.
mpservice.mpserver.Worker.__init__
loses parameterbatch_size_log_cadence
and gets new parametercpu_affinity
, which also becomes an attribute of the worker instance.
- Removed some deprecated code.
mpservice.mpserver.Worker
gets new methodcleanup
.
- Bug fix in
mpservice.multiprocessing.Pool
. - Finetune about shutdown of the background threads supporting
mpservice.multiprocessing.SpawnProcess
.
-
Minor tweak on
mpserver
detail.It happens in one application that some requests get stuck in the server "backlog", whereas by design this should never happen (in reasonable time every input unit flows through the system and comes out of the output queue, at which time clears its bookkeeping entry in the backlog). The tweak hopefully helps debugging this situation.
- Bug fix in
ServerBacklogFull
class definition.
- Export
isiterable
andisasynciterable
inmpservice.streamer
. mpservice.threading.Thread.raise_exc
was renamed tothrow
.- Bug fix in
mpservice.multiprocessing.SimpleQueue
. - Bug fix and fine-tuning related to stopping
uvicorn
andmpservice.mpserver
servers.
- Customize
Process
andThread
classes inmpservice.mpserver
to log unhandled BaseException, if any.
- Bug fix in
mpservice.experimental.streamer.EagerBatcher
. EagerBatcher
is moved out ofexperimental
intompservice.streamer
.
- Further finetune of importing paths of things, esp in
mpservice.multiprocessing
. - Some improvements to documentation.
- Adjustment to the importing of things in
mpservice.multiprocessing
. Some changes are breaking.mpservice.multiprocessing.context
has becomempservice.multiprocessing._context
.mpservice.multiprocessing.util
has been removed.
- New http serving code in
mpservice.http
designed for multiple worker processes managed byuvicorn
(as opposed to multiple worker processes managed bympservice.mpserver
). - Removed dependency on
asgiref
. Stream.groupby
now behaves like the standarditertools.groupby
in that the subgroups it yields are generators rather than lists.Stream.{map, filter}
now can take asyncfunc
arguments.- New method
Stream.shuffle
.
- Bug fix.
- Remove previously deprecated code.
- Deprecated
mpservice.multiprocessing.util.CpuAffinity
. - Refinement to
get_shared_thread_pool
andget_shared_process_pool
. - Removed the constant
MAX_THREADS
frommpservice.threading
.
- Removed "IterableQueue" and variants, as well as
StreamServer
, frommpservice.experimental
. - Revised
mpservice.experimental.streamer.EagerBatcher
to not useIterableQueue
. This makes it simpler and more usable.
- Finetune exit status handling of
SpawnProcess
. mpservice.mpserver.StreamServer
was moved intompservice.experimental.mpserver
.- Parameter
main_cpu
to a few functions inmpservice.mpserver
was removed. - Default value of parameter
timeout
tompservice.mpserver.Server.stream
andmpservice.mpserver.AsyncServer.stream
were changed from 600 to 3600, so that user almost never need to specify this parameter. - in
mpservice.mpserver
, if a Worker fails to start, the exception will propagate throughServlet.start
intoServer.__enter__
.
mpservice.mpserver.{ProcessServlet, ThreadServlet}
get new parameterworker_name
.- Added trivial subclasses of the standard
queue.{Queue, SimpleQueue}
,asyncio.Queue
,multiprocessing.queues.{Queue, SimpleQueue}
; the subclasses are generic, hence can take annotations for the type of the elements contained in the queues. - New subpackage
mpservice.experimental
; moved all the few types ofIterableQueue
as well asmpservice.streamer.EagerBatcher
into it. - Import some subpackages in
__init__.py
.
- New class
mpservice.streamer.EagerBatcher
. - New class
mpservice.mpserver.StreamServer
. This intends to eventually replace and deprecatempservice.mpserver.Server.stream
, but the current version has not shown speed benefits yet, despite being simpler. - Speed improvements to
mpserver
andstreamer
. mpservice._streamer.{IterableQueue, IterableProcessQueue, AsyncIterableQueue}
were moved intompservice.queue
,mpservice.multiprocessing.queues
,mpservice.asyncio
respectively and all renamed toIterableQueue
.- A few utility classes in
mpservice._streamer
are now exposed inmpservice.streamer
, includingBatcher
,Unbatcher
,Buffer
.
IterableQueue
,IterableProcessQueue
,AsyncIterableQueue
became generic with an element type parameter.- Parameter
cpus
toProcessServlet.__init__
now accepts an int, indicating number of unpinned processes. - Use more reliable way to infer whether a
Stream
object is sync or async iterable. - Fixed issues in documentation generation.
- New methods
mpservice.threading.Thread.{raise_exc, terminate}
. - New functions
mpservice.threading.{wait, as_completed}
. - Enhancements to
mpservice.multiprocessing.server_process
esp regarding "hosted" data. - Do not raise exception if a
mpservice.multiprocessing.context.SpawnProcess
was terminated by.terminate()
. The previous behavior tends to raise exception when aServerProcess
shuts down. mpservice.mpserver.Worker
adds support forpreprocess
.- Revised implementation of
mpservice.multiprocessing.context.SpawnProcess
to use a Future to supportwait
andas_completed
. - New functions
mpservice.multiprocessing.{wait, as_completed}
. - Renamed
mpservice._streamer.{IterQueue, IterProcessQueue, AsyncIterQueue}
to{IterableQueue, IterableProcessQueue, AsyncIterableQueue}
. - Finetune implementation of
mpservice._stramer.{IterableQueue, IterableProcessQueue, AsyncIterableQueue}
. - Made
mpservice._streamer.Stream
generic to allow type-annotatingStream[T]
.
- Re-orged
mpservice.multiprocessing
into a sub-package as the module has grown considerably and may grow further. mpservice.mpserver.{Server, AsyncServer}
bug related to "gather-output" and "notify" requesters.- Enhancements to
mpservice.mpserver.multiprocessing.ServerProcess
(in progress).
- Finetune to
mpservice.multiprocessing.ServerProcess
and its shared-memory facilities. - Fix a bug in
mpservice.mpserver.{Server, AsyncServer}
related to input buffer. - Finetune
mpservice.mpserver.{Server, AsyncServer}
internals.
- Breaking changes to
mpservice.mpserver.Server
API: the class is split into two classes:Server
andAsyncServer
. mpservice.mpserver.Server.call
got new parameterbackpressure
(previously only the async call has this parameter).- Finetuned waiting and sleeping logic in
mpservice.mpserver.{Server, AsyncServer}
; useCondition
to replace sleeping. - Made sure (or confirmed) that
mpservice.mpserver.Server.call
and ``mpservice.mpserver.Server.stream` are thread-safe. mpservice.streamer.Stream.peek
finetune of printing; got new parameterprefix
andsuffix
.- Refinements to classes
mpservice.streamer.{IterQueue, IterProcessQueue, AsyncIterQueue}
. - Refinements to
mpservice.multiprocessing.ServerProcess
: further diverge from the standard class. - Initial support for "shared memory" in the class
mpservice.multiprocessing.ServerProcess
.
- New function
mpservice.streamer.tee
. - New class
mpservice.streamer.IterProcessQueue
. - Removed the "cancellation" "Event" mechanism in
mpservice.mpserver.Server
that was introduced in 0.12.7. There are two main reasons for the removal: (1) thempservice.multiprocessing.manager.Event
that is checked by every worker seems to have considerable overhead although I did not measure it; (2) there is difficulty in maintaining a reference to theEvent
object in the event of cancellation to ensure any worker that tries to access it will do so before it is gone in the manager process; this issue manifests asKeyError
during unpickling when the object is being retrieved from a multiprocessing queue.
- Removed
mpservice.mpserver.{ProcessWorker, ThreadWorker}
; just useWorker
. - Renamed
mpservice.mpserver.make_threadworker
tompservice.mpserver.make_worker
. mpservice.mpserver.Server
got new methodasync_stream
.- New classes
mpservice.streamer.IterQueue
,mpservice.streamer.AsyncIterQueue
. - Minor tuning of
mpservice.multiprocessing.ServerProcess
.
- Methods
mpservice.streamer.Stream.{async_parmap, parmap_async}
are dropped and merged intoparmap
. - Function
mpservice.http.run_app
.
mpservice.streamer.Stream.parmap
: parameterexecutor
became named only.mpservice.multiprocessing.Manager
was renamedServerProcess
.- Parameter
backlog
tompservice.mpserver.Server.__init__
was renamed tocapacity
.
mpservice.streamer.Stream
added extensive support for async.- Methods
mpservice.streamer.Stream.{to_sync, to_async, __aiter__}
. - Method
mpservice.mpserver.Server.full
and propertiesmpservice.mpserver.Server.{capacity, backlog}
. - Added capabilities to cancel a item submitted to
mpservice.mpserver.Server
and halt its processing in the pipeline as soon as practical. - Made
mpservice.mpservice.multiprocessing
more close to the standardmultiprocessing
in terms of what can be imported from it. - New parameter
name
toSpawnContext.Manager
. SpawnProcess
captures warnings to logging.
- New method
mpservice.streamer.Stream.async_parmap
with corresponding classAsyncParmapper
.
- The cleanup or "finalize" logic of
mpservice.streamer.{Buffer, Parmapper, AsyncParmapper, ParmapperAsync}
.
- New method
mpservice.streamer.Stream.parmap_async
, taking an async worker function.
- Bug in deprecation warning in
util
andserver_process
.
-
Refactored
util
to split it into modulesmpservice.multiprocessing
,mpservice.threading
,mpservice.concurrent.futures
to have some imports correspond to those in the standard libs.util
is deprecated. -
server_process
was merged intompservice.multiprocessing
.
ProcessServlet
andThreadServlet
lost parametername
to__init__
.- class
ProcessLogger
.
- The modules
mpserver
,multiprocessing
,threading
each defines its ownTimeoutError
exception class.
mpservice.mpserver.Worker
got new parameterworker_index
to__init__
, which is automatically provided by the parentProcessServlet
orThreadServlet
. Subclasses ofWorker
should be sure to accept this parameter in their__init__
.- function
mpservice.multiprocessing.get_context
. mpservice.multiprocessing.Manager
gets two init parametersprocess_name
andprocess_cpu
.mpservice.concurrent.futures.ProcessPoolExecutor
gets parametermp_context
to be compatible with the standard lib, but with a different default that ismpservice.multiprocessing.MP_SPAWN_CTX
.
mpservice.multiprocessing.SpawnProcess
finetune onjoin
and finalization cleanup.
- Remove dependency on
overrides
.
mpservice.util.{Process, Thread}
have customized methodjoin
that will raise the exception raised in the child process or thread.
mpservice.util.{Process, Thread}
finetune related to exceptions.mpservice.util.{Process, Thread}
: parameterloud_exception
moved from__init__
tosubmit
.streamer
finetune related to exception printout in worker threads/processes.
SpawnProcess
does not forward logs to the main process if the root logger has any handler configured.
SpawnProcess
andThread
in "loud_exception" mode do not print exception info if the exception isSystemExit(0)
. This is the case when a "server process" exits.
mpservice.mpserver.Server.stream
retries on enqueue timeout.- Finetune to waiting times in
Server
.
EnsembleServlet
gets new parameterfail_fast
to control behavior when ensemble members return exceptions.- New exception class
EnsembleError
. - Added
mpservice.util.Process
, which is an alias toutil.SpawnProcess
. - Refinements to
mpservice.util.SpawnProcessPoolExecutor
. - Added
mpservice.util.ProcessPoolExecutor
, which is an alias tompservice.util.SpawnProcessPoolExecutor
. - New class
mpservice.util.ThreadPoolExecutor
. - New class
mpservice.mpserver.SwitchServlet
.
mpservice.util.{Thread, SpawnProcess}
print out tracback upon exception, making errors in concurrent code more discoverable. This functionality was there previously but it was buggy.- Fixed a deadlock situation during the shutdown of streamer
parmap
.
- Bug in
mpservice.mpserver.EnsembleServlet
.
- Deprecated context manager on
Streamer
. Instead, use the object directly. - Deprecated function
mpservice.util.is_exception
.
Streamer.peek
parameterinterval
: default changed to 1 from 1000.- Class
Streamer
is renamedStream
; the old classStream
was removed.
mpservice.streamer.Parmapper.__init__
takes two new argumentsexecutor_initializer
andexecutor_init_args
.- Simplifications to the implementation of
streamer.py
, making use ofGeneratorExit
and removing classStream
. - New utility functions
mpservice.util.get_shared_thread_pool
,mpservice.util.get_shared_process_pool
.
The two largest efforts of this release are documentation and "streamer" refactor.
mpservice.streamer.Streamer.{drop_first_n, peek_random, drop_if, keep_if}
, and corresponding classesDropper
.mpservice.streamer.Streamer.drop_exceptions
.
mpservice.streamer.Streamer.transform
: parameterconcurrency
used to default to 1 (i.e. no concurrency), now defaults to higher numbers (i.e. with concurrency).mpservice.mpserver.{Sequential, Ensemble}
were renamed toSequentialServlet
andEnsembleServlet
respectively.mpservice.streamer.Streamer.drain
: return count of elements processed, instead of the tuple of element count and exception count.mpservice.streamer.Streamer.peek
was refactored.mpservice.streamer.Streamer.transform
was renamed toparmap
.- Relaxed the requirement for using context manager with
Streamer
. Streamer.parmap
uses processes by default, instead of threads.
- Enhanced documentation. Started to host generated doc on Read the Docs.
- New class
mpservice.mpserver.CpuAffinity
. - New method on
mpservice.streamer.Streamer
and corresponding classes:filter
andFilter
,tail
andTailor
,map
andMapper
,groupby
andGrouper
. - New method
mpservice.streamer.Streamer.filter_exceptions
,mpservice.streamer.Streamer.accumulate
.
- Upgrade for a breaking change in
uvicorn
0.19.0.
Streamer
implementation finetune, mainly about worker thread/process finalization.Streamer
removes methods that are trivial (so user can implement them if needed) and unnecessary or not very needed:collect
,drop_nones
,keep_every_nth
,keep_random
,log_every_nth
.Streamer.log_exceptions
was renamedpeek_exceptions
with minor changes.- Parameter
shed_load
tompservice.mpserver.Server.async_call
is renamed tobackpressure
.
mpserver
wait-time fine tunning.mpservice.mpserver.Server.async_call
gets new parametershed_load
with defaultTrue
.- New exception class
PipelineFull
inmpserver
.
RemoteException
is re-written with much simplifications; the class is moved fromremote_exception
toutil
; the moduleremote_exception
is removed.- Enhancements to
SpawnProcess
. - Improvements to util.ProcessLogger`.
- The new constant
mpservice.util.MP_SPAWN_CTX
is a customization to the standard spawn context that usesSpawnProcess
instead ofProcess
. - Use spawn method or
SpawnProcess
exclusively or by default in various places in the code. Streamer.transform
gets new parameterexecutor
to support multiprocessing for CPU-bound operators.- The module
server_process
is re-written. - The module
named_pipe
is renamedpipe
.
mpservice.util.ProcessLogger
gets context manager methods.- New class
mpservice.util.SpawnProcess
.
- Add dependency
asgiref
. Previously we've relied on gettingasgiref
fromuvicorn
dependency, which is a bad idea. Recently,uvicorn
removed its dependency onasgiref
. - Reduce the default frequency of resource utilization logs.
- Refinement and simplification to
streamer
. - Refinement to
server_process
.
- Added
mpservice.mpserver.ThreadWorker
andThreadServlet
. - Simplified
mpserver
parameter for CPU pinning spec. - Added log on worker process CPU/memory utilization in
mpserver
.
- Refactor to
mpserver
with API changes. New design allows flexible composition of sequential and ensemble setups, leading to considerable enhancements in capability and flexibility. There are also considerable improvements to the implementation (in terms of simplicity, elegance, robustness). - Replaced all uses of
time.monotonic
bytime.perf_counter
, which has much higher resolution. - Added module
named_pipe
.
- Added (or brought back) parameter
backlog
toMPServer
. - Implimentation improvements: simplified utitlity queues; removed error pipe of MPServer.
- Finetune to
EnsembleServer
: ensemble elements could beRemoteException
objects, i.e. failure of one ensemble component will not halt or invalidate the other components.
- By default,
MPServer
uses the new, custom queue typeUnique
for faster buildup of batches for servlets. RemovedZeroQueue
andBasicQueue
. - Simplified timeout in
mpserver
.EnqueueTimeout
is gone;TotalTimeout
is renamedTimeout
. The parametersenqueue_timeout
andtotal_timeout
are combined intotimeout
. ServerProcess
gets new parameterctx
for multiprocessing context.
- Added alternative multiprocessing queues, namely
BasicQueue
,FastQueue
andZeroQueue
, in an attempt to improve service speed, expecially batching. This topic is still under experimentation.ZeroQueue
is not ready for use. - Changed socket encoder from 'orjson' to 'pickle'.
- Removed
max_queue_size
parameter ofMPServer
; use unbounded queues. MPServer
parametercpus
renamed tomain_cpu
with default value0
.
- Minor fine-tuning and documentation touch-ups.
- Rewrote
socket
to be fully based onasyncio.streams
. - Refactored socket server side to make its usage similar to a web app.
- Refactored
_streamer
for much improved robustness and simplicity. - Streamer API changes, mainly:
- use context manager;
- operations modify the hosting object in-place, hence eliminating the need to assign intermediate transforms to new names.
Streamer.transform
now accepts both sync and async functions as the "operator".- Improved
MPServer.stream
andSocketClient.stream
; removedMPServer.stream2
. - Rewrote
RemoteException
, especially for pickle-safety. SocketServer
shutdown handling.- Removed
MPServer.{start, stop}
; use__enter__/__exit__
. - Removed some contents of
util
.
- Add async-based
MPServer.stream2
. - Improve printing of RemoteException in
__exit__
. - SocketServer creates directory path as needed at startup.
- Small improvements.
- Removed async streamer.
- Simplified implementation of the
transform
method of streamer.
- Simplify
MPServer.stream
; removeMPServer.async_stream
; the functionality ofasync_stream
is provided bystream
. - Make more utility functions available in
util
. - Simplify
_async_streamer
.
mpservice.http_server
was renamed tompservice.http
.- Initial implementation of socket client/server.
mpserver
fine tune, esp about graceful shutdown.- Use
overrides
to help keep sanity checks on class inheritance. - Bug fixes in streamer.
- Handle logging in multiprocessing.
- Use 'spawn' method for process creation.
- Refactored and simplified test/build process.
- Removed
mpservice.http_server.run_local_app
. - Minor bug fixes.
- Improvements to the utilities in
mpservice.http_server
, esp regarding service shutdown.
- Requirement on
uvicorn
changes touvicorn[standard]
, which usesuvloop
.
- Reworked error propagation in streamer; fixed bugs therein.
- Renamed
exception
toremote_exception
. - Corner-case bug fixes in
MPServer
. - Increase queue size in
ConcurrentTransformer
.
- Refactor the
MPError
class, with a renaming toRemoteException
.
- Refactor the
MPError
class.
- Relax version requirements on dependencies.
BackgroundTask
refinements, esp about support for asyncio.
BackgroundTask
bug fix.
BackgroundTask
refactor.
MPServer.start
starts the servlets sequentially by default.
- Bug fix in
mpservice.streamer.{Stream, AsyncStream}.batch
. - Change Python version requirement from 3.7 to 3.8, due to the use of
parameter
name
inasyncio.create_task
.
- Revise
background_task
API.
- Rewrite
streamer
andasync_streamer
to avoid queues in simple "pass-through" ops, such asdrop_if
,log_exceptions
. - Minor improvements to
http_server
. - Possible bug fix related to
total_timeout
. - Added new module
background_task
.
- Bug fix.
mpservice.mpserver.Servlet.__call__
is renamed tocall
.
- Add
mpservice.mpserver.EnsembleServer
to implement ensembles; renameServer
toSequentialServer
. - Add
mpservice.mpserver.SimpleServer
. - Revise
cpu
specification inmpserver
.
mpservice.mpserver.Server
gets a sync API, in addition to the existing async API.mpservice.mpserver.Server
gets sync and async stream methods.
Streamer API fine-tuning and bug fixes.
Added sync streamer.
Refactor the async streamer API and tests.
Fine tuning on streamer
.
Added:
mpservice.streamer.{transform, unordered_transform}
get new parameterreturn_exceptions
. Similarly,drain
gets new parameterignore_exceptions
.
Added:
streamer
Changed:
Servlet.process
is renamed toServlet.__call__
.mpservice._http
renamed tompservice.http_server
with enhancements.mpservice._server_process
renamed tompservice.server_process
.
Changed:
- Replaced machine learning terminologies ('model', 'predict', etc) in namings by generic names. This broke public APIs.
- Guarantee worker initiation (running in other processes) before service startup finishes.
Added:
ModelService.a_predict
gains new parametersenqueue_timeout
andtotal_timeout
, with default values 10 and 100 seconds, respectively.