2
0
Fork 0
lighttpd2/include/lighttpd/worker.h

138 lines
3.9 KiB
C
Raw Normal View History

#ifndef _LIGHTTPD_WORKER_H_
#define _LIGHTTPD_WORKER_H_
#ifndef _LIGHTTPD_BASE_H_
#error Please include <lighttpd/base.h> instead of this file
#endif
2009-11-01 14:43:12 +00:00
struct lua_State;
typedef struct liStatistics liStatistics;
struct liStatistics {
2008-09-25 20:49:32 +00:00
guint64 bytes_out; /** bytes transfered, outgoing */
guint64 bytes_in; /** bytes transfered, incoming */
2008-09-25 20:49:32 +00:00
guint64 requests; /** processed requests */
guint64 active_cons_cum; /** cummulative value of active connections, updated once a second */
2008-09-25 20:49:32 +00:00
guint64 actions_executed; /** actions executed */
/* 5 seconds frame avg */
guint64 requests_5s;
guint64 requests_5s_diff;
guint64 bytes_out_5s;
guint64 bytes_out_5s_diff;
guint64 bytes_in_5s;
guint64 bytes_in_5s_diff;
guint active_cons_5s;
ev_tstamp last_avg;
/* peak values from 5s avg */
struct {
guint64 requests;
guint64 bytes_out;
guint64 bytes_in;
guint active_cons;
} peak;
2008-09-25 20:49:32 +00:00
/* updated in timer */
guint64 last_requests;
double requests_per_sec;
ev_tstamp last_update;
};
#define CUR_TS(wrk) ev_now((wrk)->loop)
/* only locks if there is more than one worker */
#define WORKER_LOCK(srv, lock) \
if ((srv)->worker_count > 1) g_static_rec_mutex_lock(lock)
#define WORKER_UNLOCK(srv, lock) \
if ((srv)->worker_count > 1) g_static_rec_mutex_unlock(lock)
typedef struct liWorkerTS liWorkerTS;
struct liWorkerTS {
time_t last_generated;
GString *str;
};
struct liWorker {
liServer *srv;
GThread *thread; /* managed by server.c */
2008-09-09 18:47:10 +00:00
guint ndx; /* worker index */
2009-11-01 14:43:12 +00:00
struct lua_State *L; /** NULL if compiled without Lua */
struct ev_loop *loop;
ev_prepare loop_prepare;
ev_check loop_check;
ev_async li_worker_stop_watcher, li_worker_suspend_watcher, li_worker_exit_watcher;
guint connections_active; /** 0..con_act-1: active connections, con_act..used-1: free connections
* use with atomic, read direct from local worker context
*/
GArray *connections; /** array of (connection*), use only from local worker context */
ev_tstamp connections_gc_ts;
GQueue closing_sockets; /** wait for EOF before shutdown(SHUT_RD) and close() */
GString *tmp_str; /**< can be used everywhere for local temporary needed strings */
/* keep alive timeout queue */
ev_timer keep_alive_timer;
GQueue keep_alive_queue;
liWaitQueue io_timeout_queue;
liWaitQueue throttle_queue;
2008-11-10 14:39:03 +00:00
guint connection_load; /** incremented by server_accept_cb, decremented by worker_con_put. use atomic access */
GArray *timestamps_gmt; /** array of (worker_ts), use only from local worker context and through li_worker_current_timestamp(wrk, LI_GMTIME, ndx) */
GArray *timestamps_local;
/* incoming queues */
/* - new connections (after accept) */
ev_async new_con_watcher;
GAsyncQueue *new_con_queue;
2008-09-25 14:59:09 +00:00
ev_timer stats_watcher;
liStatistics stats;
/* collect framework */
ev_async collect_watcher;
GAsyncQueue *collect_queue;
GQueue job_queue;
ev_timer job_queue_watcher;
2009-03-01 20:16:58 +00:00
GAsyncQueue *job_async_queue;
ev_async job_async_queue_watcher;
liStatCache *stat_cache;
2009-11-22 17:50:11 +00:00
GByteArray *network_read_buf; /** internal temporary buffer for network.c */
};
2009-07-09 20:17:24 +00:00
LI_API liWorker* li_worker_new(liServer *srv, struct ev_loop *loop);
LI_API void li_worker_free(liWorker *wrk);
2009-07-09 20:17:24 +00:00
LI_API void li_worker_run(liWorker *wrk);
LI_API void li_worker_stop(liWorker *context, liWorker *wrk);
LI_API void li_worker_suspend(liWorker *context, liWorker *wrk);
2009-07-09 20:17:24 +00:00
LI_API void li_worker_exit(liWorker *context, liWorker *wrk);
2009-07-09 20:17:24 +00:00
LI_API void li_worker_new_con(liWorker *ctx, liWorker *wrk, liSocketAddress remote_addr, int s, liServerSocket *srv_sock);
2009-07-09 20:17:24 +00:00
LI_API void li_worker_check_keepalive(liWorker *wrk);
LI_API GString* li_worker_current_timestamp(liWorker *wrk, liTimeFunc, guint format_ndx);
/* shutdown write and wait for eof before shutdown read and close */
2009-07-09 20:17:24 +00:00
LI_API void li_worker_add_closing_socket(liWorker *wrk, int fd);
/* internal function to recycle connection */
LI_API void li_worker_con_put(liConnection *con);
#endif