Commit Graph

44 Commits

Author SHA1 Message Date
Joris Vink 548348f553 2018 2018-01-20 22:51:06 +01:00
Joris Vink 4ad50caa29 Large changes to the memory subsystem in kore.
- Change pools to use mmap() for allocating regions.
- Change kore_malloc() to use pools for commonly sized objects.
  (split into multiple of 2 buckets, starting at 8 bytes up to 8192).
- Rename kore_mem_free() to kore_free().

The preallocated pools will hold up to 128K of elements per block size.

In case a larger object is to be allocated kore_malloc() will use
malloc() instead.
2016-07-12 13:54:14 +02:00
Joris Vink 82a9e6ef59 Formatting and unbreaking NOHTTP builds. 2016-02-01 20:02:02 +01:00
Stig Telfer 2ac6e7d41d Merge branch 'master' into oneswig 2016-01-24 13:46:38 +00:00
Stig Telfer fd0ddca46c Add cleanup function for platform_event on BSD systems 2016-01-22 11:26:56 +00:00
Stig Telfer ec73c35952 Add missing C library headers 2016-01-22 11:08:13 +00:00
Joris Vink c4b1206ae3 Bump copyright to 2016. 2016-01-04 12:58:51 +01:00
Joris Vink d3332d5921 Add kore_platform_schedule_write(). 2015-12-09 21:29:44 +01:00
Joris Vink 961a2e3685 Allow apps to override connection handling.
Setting the handle callback allows your application
to take care of network events for the connection.

Look at the connection state and flags to determine
if read/write is possible and go from there.

See kore_connection_handle() for more details.
2015-12-01 20:55:00 +01:00
Joris Vink 0e3271cf9d Add EV_CLEAR to the bsd event code for kqueue.
This was missing and makes dealing with events easier.
2015-06-23 18:16:19 +02:00
Joris Vink 49ca95f390 Add our messaging framework.
With this framework apps can now send messages between worker processes.

A new API function exists:
	int kore_msg_register(u_int8_t id, void (*cb)(const void *, u_int32_t);

This API call allows your app to register a new message callback for a given ID.

You can then send messages on this ID to other workers using:
	void kore_msg_send(u_int8_t id, void *data, u_int32_t length);

This framework will interally be used for a few things such as allowing
websocket data to broadcasted between all workers, adding unified caching
and hopefully eventually moving the access log to this as well.

Some internals have changed with this commit:
	* worker_clients has been called connections.
	* the parent now initializes the net, and event subsystems.
	* kore_worker_websocket_broadcast() is dead.
2015-06-22 21:13:32 +02:00
Joris Vink 5228fe1cbc Fix typo in configuration option worker_accept_treshold.
There is no backwards comptabile option available.

Fixes #53
2015-05-18 12:20:28 +02:00
Joris Vink 6be54040f3 Use kevent() to schedule an event immediately.
Instead of merging it in under the kevent() call under
the event loop. Strange side effects are showing on OSX
under heavy load.
2015-04-24 11:45:00 +02:00
Joris Vink b869041a14 Introduce new config option worker_accept_treshold
This configuration option limits the maximum number
of connections a worker process can accept() in a single
event loop.

It can be used to more evenly spread out incoming connections
across workers when new connections arrive in a burst.
2015-04-23 10:24:00 +02:00
Joris Vink 4c39ac43fb Properly deal with accept() failing.
In cases where accept() failed Kore would not relinquish the
lock towards other worker processes.

This becomes evident when dealing with a high number of concurrent
connections to the point the fd table gets full. In this scenario
the worker with the full fd table will spin on attempt to accept
newer connections.

As a bonus, Kore now has allows exactly up to worker_max_connections
of connections per worker before no longer attempting to grab the
accept lock.
2015-04-20 15:17:42 +02:00
Joris Vink 097a1166df Improve very heavy load handling.
Introduces two new configuration knobs:
	* socket_backlog (backlog for listen(2))
	* http_request_limit

The second one is the most interesting one.

Before, kore would iterate over all received HTTP requests
in its queue before returning out of http_process().

Under heavy load this queue can cause Kore to spend a considerable
amount of time iterating over said queue. With the http_request_limit,
kore will process at MOST http_request_limit requests before returning
back to the event loop.

This means responses to processed requests are sent out much quicker
and allows kore to handle any other incoming requests more gracefully.
2015-04-09 15:29:44 +02:00
Joris Vink af865abede Bump copyright to 2015 2015-04-07 13:08:26 +02:00
Joris Vink d6ab1d7445 Add rudimentary timers to Kore.
Timers are in ms resolution and are added using
kore_timer_add(cb, interval, flags).

Both oneshot timers and continious timers are supported.
2015-04-06 18:54:35 +02:00
Joris Vink 27b4447a30 Allow workers to bind to specific CPUs on FreeBSD. 2014-10-26 22:41:55 +01:00
Joris Vink 9512805c04 spacing 2014-10-26 22:11:13 +01:00
Joris Vink 6de0f8568a Rework net, worker and some http internals.
- The net code no longer has a recv_queue, instead reuse same recv buffer.
- Introduce net_recv_reset() to reset the recv buffer when needed.
- Have the workers spread the load better between them by slightly
  delaying their next accept lock and giving them an accept treshold
  so they don't go ahead and keep accepting connections if they end
  up winning the race constantly between the workers.
- The kore_worker_acceptlock_release() is no longer available.

- Prepopulate the HTTP server response header that is added to each
  response in both normal HTTP and SPDY modes.
- The path and host members of http_request are now allocated on the heap.

These changes overall result better performance on a multicore machine,
especially the worker load changes shine through.
2014-10-22 21:16:49 +02:00
Joris Vink 79b3ccfe7d kqueue event list should hold worker_max_connections * 2 2014-10-16 21:45:43 +02:00
Joris Vink 693a07250f bump copyright years 2014-10-14 16:18:23 +02:00
Joris Vink 7771adbec2 Allow applications to create new connections in our event loop. 2014-09-17 08:25:45 +02:00
Joris Vink 26d4d5d63b Rework the accept lock.
Kore no longer passes the accept lock to the "next in line"
worker but instead all workers will attempt to grab the lock
if they can.

Also remember if we had the lock previous iteration of the
event loop and don't constantly disable/enable the accepting sockets.

Makes Kore scale even better across multiple cpu's.
2014-07-30 15:20:09 +02:00
Joris Vink 478c008c99 Missing parts from last commit 2014-07-28 23:35:12 +02:00
Joris Vink 2c6b5e6b0f Normalize kore_*.h headers 2014-07-03 22:14:46 +02:00
Joris Vink a54d04eb8a Add task glue for BSD as well 2014-06-30 14:43:34 +02:00
Joris Vink 723c99b65e Move kore_pgsql.h into includes/ directly.
Much like kore_tasks.h
2014-06-30 08:42:18 +02:00
Joris Vink 89b603c247 Support postgresl under the bsds 2014-04-02 00:06:24 +02:00
Joris Vink 3eb3665600 Detect right amount of cpu's available under osx. From Vaibhav Bhembre via github. 2013-07-28 19:21:49 +02:00
Joris Vink 659e19f92f add IPv6 support and support for multiple listeners. 2013-07-27 20:56:15 +02:00
Joris Vink 91b839f355 Add OSX support, buildable via "make osx".
Make sure you have OpenSSL 1.0.0d+ (available from Macports) installed.

Based on diff from Vaibhav Bhembre via github
2013-07-17 20:19:44 +02:00
Joris Vink f54e7ace83 do not try to accept if accept has failed, but instead let kore continue 2013-07-13 22:24:00 +02:00
Joris Vink f59e94a7b6 Add spdy_session_teardown() which can properly teardown a SPDY session.
Use this throughout the spdy code to propagate session errors (if any) occur.

At the same time fix BSD's missing CONN_WRITE_BLOCK
2013-07-13 19:56:38 +02:00
Joris Vink 7df5339c8d Properly fix bsd.c, sigh. 2013-07-06 21:05:17 +02:00
Joris Vink 3c6169a861 bring bsd into sync 2013-06-27 12:37:14 +02:00
Joris Vink 2fc5233358 Rework the way worker processes give each other the accept lock.
Instead of waiting until one worker is filled up on connections
the workers find the next lowest loaded worker and will hand
over the lock to them instead. This will cause a nicer spread of load.

Instead of running one accept per event loop, we attempt to accept
as many as worker_max_connections allows.

Refactor net sending/recv code a bit.
2013-06-27 00:22:48 +02:00
Joris Vink 0dda6f996f Add a form of synchronization between what worker will be accepting
new connections and which ones will not be notified for it.

Fixes the thundering herd problem, and nicely spreads out load between
all the workers equally. A configuration option (workers_max_connections)
is available to tweak how many connections a worker will have before
giving up the accept lock.

Two ways are added to this commit for access locking:
- Locking via semaphores.
- Locking via GCC's builtin atomic methods.

The default is running with semaphores disabled (OpenBSD cannot do
sem_init() with pshared set to 1, which is required).

If you want to use semaphores add KORE_USE_SEMAPHORES to CFLAGS,
and -lpthread to LDFLAGS in the Makefile.

Other fixes:
- BSD: add a timeout to kevent().
- Merge kore_worker_wait together, linux knows waitpid() as well.
- Send the correct SIGQUIT signal to workers instead of SIGINT.
- Fix kore_time_ms().
- Log fatal worker messages in syslog.
- Refactor code even more.
- Do not free our own kore_worker structure.
2013-06-26 16:37:22 +02:00
Joris Vink 315f964abd correct typo 2013-06-26 11:20:25 +02:00
Joris Vink 3e5c17b8a3 refactor code quite a bit. 2013-06-26 11:18:32 +02:00
Joris Vink a1b400c400 Add access logging to Kore. 2013-06-24 09:36:40 +02:00
Joris Vink c49622e4ae do not schedule kqueue events if we've reached the limit of changelist. 2013-06-20 23:29:26 +02:00
Joris Vink 25f1ab9865 Add BSD kqueue(2) support. Compile with make bsd (or make linux for linux) 2013-06-17 23:39:17 +02:00