mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
Loading...
Searching...
No Matches
render_submit_queue.h File Reference
#include <sys/time.h>
#include "render_config.h"

Go to the source code of this file.

Classes

struct  qItem
 Singly linked queue node representing a metatile job to submit to renderd. More...
struct  speed_stat
 Aggregated rendering latency and throughput counters for a single zoom level. More...
struct  speed_stats
 Per-zoom-level collection of rendering speed statistics (0 through MAX_ZOOM). More...

Functions

int make_connection (const char *spath)
 Open a stream connection to renderd over a Unix domain socket or TCP/IP socket.
void check_load (void)
 Throttle worker submission while the system 1-minute load average meets or exceeds maxLoad.
void display_rate (struct timeval start, struct timeval end, int num)
 Log the elapsed time and average throughput (tiles/sec) for a batch of rendered tiles.
void enqueue (const char *xmlname, int x, int y, int z)
 Enqueue a metatile render request onto the bounded worker submission queue.
void finish_workers (void)
 Signal all worker threads to finish remaining queued items and join them.
void print_statistics (void)
 Log per-zoom-level minimum, average, maximum, and cumulative render times.
void spawn_workers (int num, const char *socketpath, int maxLoad)
 Initialize synchronization primitives and spawn the pool of render-client worker threads.
void * thread_main (void *arg)
 Worker thread main loop that fetches queued requests and submits them to renderd.
void wait_for_empty_queue (void)
 Block the calling thread until all currently queued items have been popped by workers.

Function Documentation

◆ check_load()

void check_load ( void )

Throttle worker submission while the system 1-minute load average meets or exceeds maxLoad.

Polls get_load_avg() in a loop and sleeps 5 seconds per iteration until system load drops below maxLoad.

◆ display_rate()

void display_rate ( struct timeval start,
struct timeval end,
int num )

Log the elapsed time and average throughput (tiles/sec) for a batch of rendered tiles.

Parameters
startTimestamp captured at the start of the batch.
endTimestamp captured at the end of the batch.
numTotal number of tiles/metatiles processed during the interval.

◆ enqueue()

void enqueue ( const char * xmlname,
int x,
int y,
int z )

Enqueue a metatile render request onto the bounded worker submission queue.

Allocates a qItem node, blocks on qCondNotFull if the queue has reached qMaxLen, appends the node to the FIFO list, and signals qCondNotEmpty to wake a waiting worker.

Parameters
xmlnameLogical map style name (duplicated onto the heap).
xTop-left tile X coordinate of the metatile.
yTop-left tile Y coordinate of the metatile.
zTile zoom level.

◆ finish_workers()

void finish_workers ( void )

Signal all worker threads to finish remaining queued items and join them.

Sets work_complete = 1, broadcasts qCondNotEmpty so idle workers exit fetch(), joins every worker thread via pthread_join(), and frees the workers handle array.

◆ make_connection()

int make_connection ( const char * spath)

Open a stream connection to renderd over a Unix domain socket or TCP/IP socket.

Interprets spath based on its leading character:

  • Leading '/': Connects to an AF_UNIX stream socket at filesystem path spath. Returns FD_INVALID if connect() fails.
  • Otherwise: Parses <host>[:<port>] (defaulting host to RENDERD_HOST and port to RENDERD_PORT), resolves addresses via getaddrinfo(), and connects over TCP. Terminates the process with exit(2) on unrecoverable socket/DNS/connect errors.
Parameters
spathSocket path (starting with '/') or TCP host[:port] specification.
Returns
Connected socket file descriptor, or FD_INVALID if a Unix socket connection failed.

◆ print_statistics()

void print_statistics ( void )

Log per-zoom-level minimum, average, maximum, and cumulative render times.

Iterates from zoom 0 through MAX_ZOOM, skipping any zoom levels with zero rendered requests, and formats millisecond timings from performance_stats as seconds.

◆ spawn_workers()

void spawn_workers ( int num,
const char * spath,
int max_load )

Initialize synchronization primitives and spawn the pool of render-client worker threads.

Configures the bounded queue capacity (qMaxLen = num) and system load ceiling (maxLoad), initializes qLock, qStatsLock, qCondNotEmpty, and qCondNotFull, and launches num threads running thread_main().

Parameters
numNumber of worker threads to spawn.
spathSocket path or host[:port] string passed to each worker thread.
max_loadMaximum system 1-minute load average allowed before throttling workers.

◆ thread_main()

void * thread_main ( void * arg)

Worker thread main loop that fetches queued requests and submits them to renderd.

Opens a dedicated connection to renderd via make_connection(), then repeatedly checks system load, pops the next command via fetch(), and submits it via process(). If the connection drops mid-flight, retries connecting every 30 seconds and re-submits the interrupted command until it succeeds.

Parameters
argconst char * socket path or host[:port] string forwarded to make_connection().
Returns
Always returns NULL once the queue is drained and work_complete is set.

◆ wait_for_empty_queue()

void wait_for_empty_queue ( void )

Block the calling thread until all currently queued items have been popped by workers.

Waits on qCondNotFull (which is signaled every time fetch() decrements qLen) until qLen reaches 0. Note that the final popped items may still be in flight inside process() when this function returns; call finish_workers() to wait for completion.