Commit Graph

98 Commits

Author SHA1 Message Date
John Cupitt 675143807a fix vips_worker_work_unit gate name 2023-01-04 16:08:57 +00:00
John Cupitt 976db37f84
Revised threading system (#3105)
* reimplement threadpool

just a set of threads that get recycled

"ninja test" passes and dzsave seems to work, though pytest fails for
some reason

* clean up threading code a bit

move base stuff into thread.c, so we have a simple

	thread -> threadset -> threadpool

layering

* start trying to revert g_threadpool

based on the original commit

* working!

nice low systime again

still need to repply cnages to threadpool.c since 80e0cc3d1

* reapply fixes from master

so threadpool.c is now up to date

* rename VipsThread as VipsWorker

a bit less confusing

* use a semaphore to count workers in a pool

* tidy up

* formatting

* dynamic threadpool sizing

based on counting the number of blocked threads in each pool

it works, but the improvement is not great :(

* add "concurrency" metadata item

so operators can hint threadpool size (dzsave especially)

* don't use thinstrip for small images

* add RGB mode to openslide

since flatten was taking 20% of CPU time for dzsave

* fix up rgb mode

now actually works

* make the tile buffer per thread

in the new openslideload rgb mode

* fix dynamic pool downsize

* mild refactoring

* fix the buffer system

oops, turned it off by mistake

* all done!

* revise changelog

* Update libvips/iofuncs/threadset.c

Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>

* Update libvips/iofuncs/threadset.c

Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>

* LSan: add libMagickCore to suppression file

* Revert "Remove mutex lock for VipsThreadStartFn"

This reverts commit 41440491.

* add VIPS_MAX_THREADS

to set a hard limit on the threadset size

* Revert "Revert "Remove mutex lock for VipsThreadStartFn""

This reverts commit 77e8520966ba79194fff3b4e648bbd295cd5c260.

* remove sslock from sink.c

* move fixed threadpool build to init

not first use

* add some doc comments

* revert test suite threshold change

* add a test for MAX_THREADS

and move the test tmp/ area into the builddir

* limit VIPS_MAX_THREADS to sane values

* use tabs rather than spaces

Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>
2022-10-26 15:25:19 +01:00
John Cupitt 34c17fc3e8 don't minimise after sink_screen expose
We were minimising at the end of threadpool_run, but this was being
called for each sinkscreen render pass, so we were throwing away the
display cache.

Instead, minimise after sink, sink_memory and sink_disc.
2022-08-05 09:12:13 +01:00
Kleis Auke Wolthuizen 0337c09700
Cleanup gettext handling (#2695)
Use GLib's i18n support instead of copying and pasting that
logic into its own header. This deprecates the vips/intl.h
header in favour of glib/gi18n.h.
2022-02-27 15:27:28 +00:00
John Cupitt 6946c3b9d9 start up threadpool later
might help php and ruby web frameworks

see eg. https://github.com/libvips/php-vips-ext/issues/42
2021-07-14 20:21:38 +01:00
Kleis Auke Wolthuizen 4c263a36e9 Don't run sinkscreen thread in threadpool
Since threads on Windows can be terminated prior to the execution
of the atexit registered functions (i.e. vips_shutdown), causing
a surprising deadlock. This thread is never recycled, so it should
be fine.

Reverts commit d1b4d12388 partially.
2021-06-07 14:39:47 +02:00
John Cupitt f637206e8d move vips_threadpool_push to internal API
and rename as vips__thread_execute()
2021-05-17 08:42:39 +01:00
John Cupitt d577b18e69 oop, dropped a comment 2021-05-11 18:10:54 +01:00
John Cupitt eef3f9568d revise threadpool comments and docs 2021-05-11 10:23:05 +01:00
Kleis Auke Wolthuizen 91a143e5c9 Swap g_private_set with g_private_replace where possible
There's a possibility that the old GDestroyNotify
handler is not called when threads are being reused.
2021-05-03 13:21:45 +02:00
Kleis Auke Wolthuizen d1b4d12388 Move sink_disc and sink_screen threads to threadpool
And deprecate the vips_g_thread_new and vips_g_thread_join
functions.
2021-05-03 13:21:45 +02:00
Kleis Auke Wolthuizen 4144049174 Remove mutex lock for VipsThreadStartFn
vips_{avg,deviate,hough,max,min,stats} are the only arithmetic functions
that do not require a mutex on the _start and/or _stop function. All
other arithmetic functions still needs this, so move it to sink instead.
2021-05-03 13:21:45 +02:00
Kleis Auke Wolthuizen 80e0cc3d12 Reuse threads by using GLib's threadpool 2021-05-03 13:21:45 +02:00
Kleis Auke Wolthuizen 2735b71292 Simplify preprocessor directives 2021-04-22 12:04:05 +02:00
Kleis Auke Wolthuizen 3ed50e0427 Cleanup configure.ac and #ifdef's 2021-03-06 15:47:07 +01:00
Lovell Fuller 117dbd888a Set minimum glib dependency version of 2.40 (March 2014) 2021-02-24 21:59:21 +00:00
Kleis Auke Wolthuizen fb61f0fa44 Define ENABLE_DEPRECATED in config.h
Do not check for VIPS_ENABLE_DEPRECATED as it could
come from an earlier version of libvips.
2020-07-07 12:16:43 +02:00
Kleis Auke Wolthuizen 230d2acfea Disable IM_* environment variables when --disable-deprecated 2020-06-18 14:15:37 +02:00
Kleis Auke Wolthuizen ceacd0bab9 s/count/af_count/
Thanks lovell!
2020-03-24 12:55:07 +01:00
Kleis Auke Wolthuizen af21838fab Use g_get_num_processors() when GLib >= 2.48.1
Also backport the patch from https://bugzilla.gnome.org/show_bug.cgi?id=748530
2020-03-24 11:11:46 +01:00
John Cupitt 96cdc5ef01 revise docs for source / target 2019-12-30 16:28:39 +00:00
John Cupitt a05a2cb52d mild refactoring of threadpool
clean up and simplify after https://github.com/libvips/libvips/pull/1240
2019-02-27 14:23:43 +00:00
jtorresfabra 8c8affab7f ThreadPool was allocating memory for threads and pools locally to the image object. As that image could not be freed from cache, for each sink operation done for that image the code was creating new pools and threads without freeing the previous one. SO the more number of threads and the more operations the bigger the hidden leak was. The fix just creates the objects not locally to that image, and also free them in its destroy functions 2019-02-27 13:01:45 +01:00
John Cupitt 3fde3cf4ba better thread leak reporting 2018-01-07 11:45:12 +00:00
Alistair Thomas 7452d046ca Update GObject introspection annotations for libvips/iofuncs directory 2017-09-30 13:31:00 +01:00
John Cupitt 7938903d22 don't size caches by image width
we were sizing buffers partly by image width, which could cause caches
to be too small if width changed down a pipeline

see https://github.com/jcupitt/libvips/issues/639
2017-04-23 08:31:16 +01:00
John Cupitt c79f64ab7d better nlines calc
better cache sizing for some image widths
2017-04-13 22:38:32 +01:00
John Cupitt e01a90f7cf revise cache sizing
we had output buffers too large, input caches too small

see https://github.com/jcupitt/libvips/issues/639
2017-04-13 16:24:51 +01:00
John Cupitt 755fa74c30 remove single-thread-first-tile thing
new seq system makes it unnecessary
2017-03-06 13:15:25 +00:00
John Cupitt e7ae10ef68 Revert "more UNBUF fixes"
This reverts commit a4d3c2a754.
2017-02-27 10:25:41 +00:00
John Cupitt a4d3c2a754 more UNBUF fixes
try to keep compat better, remove the single-thread-first-tile idea
2017-02-21 16:53:48 +00:00
John Cupitt 2be0b97dce switch to g_warning()_/g_info()
we had vips_warn() and vips_info(), but they are a bit crappy ... switch
to g_warning() and g_info() instead

see https://github.com/jcupitt/libvips/issues/544
2017-01-03 15:52:27 +00:00
John Cupitt 87928d4eba oops, failed merge 2016-10-28 17:26:13 +01:00
John Cupitt e715c62e27 Merge branch '8.4' 2016-10-28 16:51:43 +01:00
John Cupitt a7edd235c4 improve compat with ancient glibs
and fix a tiny threading leak
2016-10-28 16:25:31 +01:00
John Cupitt 26a534eeac count threads for leak test
see https://github.com/jcupitt/libvips/issues/542
2016-10-19 10:52:18 +01:00
John Cupitt 9f97d7b4ff fix out of threads crash
we crashed if thread create failed, see

https://github.com/jcupitt/libvips/issues/542
2016-10-19 09:59:12 +01:00
John Cupitt ccfe4cb215 seems to work?
needs stress testing still

see https://github.com/jcupitt/libvips/issues/535
2016-10-10 15:12:12 +01:00
John Cupitt 271d8656e9 use round() rather than rint() where appropriate
rint() rounds to nearest even, rather than nearest ... in some cases,
like geometry transforms, we want strict nearest
2016-08-20 12:59:41 +01:00
John Cupitt 6a445ea9c8 more vips image read fixing
thanks AFL!
2016-05-17 21:58:52 +01:00
John Cupitt 1f93efd65d fix more compiler warnings 2016-01-26 16:41:03 +00:00
John Cupitt 07a1903390 use g_assert_not_reached()
we were using g_assert(0) ... g_assert_not_reached() makes the
intention clearer
2016-01-24 13:21:53 +00:00
John Cupitt f5a77dd80d start some notes on threading 2015-04-27 10:57:27 +01:00
John Cupitt 339f268200 add some API for args, fix a docs messup 2015-03-02 22:02:33 +00:00
John Cupitt 0114afa5fb limit nthr on tiny images
we always made N threads for a threadpool ... we could end up making
loads of threads we never used if the image was tiny

for very small images, limit the number of threads we make
2014-07-25 14:51:29 +01:00
John Cupitt 91cb6cd8c4 remove an old comment 2014-07-25 14:13:33 +01:00
John Cupitt cbc60722fc skipahead is back
thanks to a new threadpool idea, see

https://github.com/jcupitt/libvips/issues/117
2014-06-10 17:44:31 +01:00
John Cupitt 5a8c9fb4ef Merge branch 'master' into dzsave-gsf 2014-04-28 14:35:18 +01:00
John Cupitt ee88271d06 use VIPS_ prefix for env vars
stuff
2014-04-26 19:59:20 +01:00
John Cupitt 325f3b9451 dzsave will write a zip file
but see the TODO in dzsave.c

- no way to pick a tile format, always jpeg
- no way to pick a container format, always zip
- needs testing
- examine memuse, how well do we work for large zips
- can we make a zip over 4gb?
2014-04-19 15:15:25 +01:00