Commit Graph

1247 Commits

Author SHA1 Message Date
Joris Vink 4d9346681a shuffle around pgsql_queue_count. 2018-02-14 13:59:23 +01:00
Joris Vink dd2dff2318 Rework HTTP and worker processes.
The HTTP layer used to make a copy of each incoming header and its
value for a request. Stop doing that and make HTTP headers zero-copy
all across the board.

This change comes with some api function changes, notably the
http_request_header() function which now takes a const char ** rather
than a char ** out pointer.

This commit also constifies several members of http_request, beware.

Additional rework how the worker processes deal with the accept lock.

Before:
	if a worker held the accept lock and it accepted a new connection
	it would release the lock for others and back off for 500ms before
	attempting to grab the lock again.

	This approach worked but under high load this starts becoming obvious.

Now:
	- workers not holding the accept lock and not having any connections
	  will wait less long before returning from kore_platform_event_wait().

	- workers not holding the accept lock will no longer blindly wait
	  an arbitrary amount in kore_platform_event_wait() but will look
	  at how long until the next lock grab is and base their timeout
	  on that.

	- if a worker its next_lock timeout is up and failed to grab the
	  lock it will try again in half the time again.

	- the worker process holding the lock will when releasing the lock
	  double check if it still has space for newer connections, if it does
	  it will keep the lock until it is full. This prevents the lock from
	  bouncing between several non busy worker processes all the time.

Additional fixes:

- Reduce the number of times we check the timeout list, only do it twice
  per second rather then every event tick.
- Fix solo worker count for TLS (we actually hold two processes, not one).
- Make sure we don't accidentally miscalculate the idle time causing new
  connections under heavy load to instantly drop.
- Swap from gettimeofday() to clock_gettime() now that MacOS caught up.
2018-02-14 13:48:49 +01:00
Joris Vink f348feef82 Add pgsql_queue_limit configuration option.
Limits the number of queued asynchronous queries kore will allow
before starting to return errors for KORE_PGSQL_ASYNC setups.

By default set to 1000.

Avoids uncontrolled growth of the pgsql_queue_wait pool.
2018-02-13 13:21:27 +01:00
Joris Vink b3a48f3c15 Let http_request_limit matter.
Before http_request_limit just constrained the number of HTTP
requests we'd deal with in a single http_process_requests() call.

But it should really mean how many maximum HTTP requests are allowed
to be alive in the worker process before we start sending 503s back.

While here, drop the lock timeout for a worker to 100ms down from 500ms
and do not allow a worker to grab the accept lock if their HTTP request
queue is full.

This makes things much more pleasant memory wise as the http_request_pool
won't just grow over time.
2018-02-13 11:56:51 +01:00
Joris Vink ce9c5a1350 reword 2018-02-05 15:21:28 +00:00
Joris Vink 548348f553 2018 2018-01-20 22:51:06 +01:00
Joris Vink a11190d638 i really don't hang out on irc anymore. 2018-01-16 18:54:45 +01:00
Joris Vink b95b623e72 Allow param blocks to be marked as "querystring"
Before params get would mean querystring and anything else
would just count toward a www-encoded body.

Now you can prefix the params block with "qs" indicating that
those configured parameters are allowed to occur in the query
string regardless of the method used.

This means you can do something like:

params qs:post /uri {
	...
}

to specify what the allowed parameters are in the querystring for
a POST request towards /uri.

inspired by and properly fixes #205.
2018-01-16 18:47:50 +01:00
Joris Vink 915b8e1d3c Use kore_bufs on the stack rather than the pools. 2018-01-15 22:31:54 +01:00
rouzier f0f1296265 Add patch support (#217)
Add PATCH to supported verbs in config and what not.
2018-01-02 22:27:59 +01:00
Joris Vink f8b3915ee1 make kore_websocket_send() slightly faster.
build the frame in a kore_buf on the stack and use net_send_stream()
to push it out rather then making yet another copy in net_send().

saves several cpu cycles before the frame starts going out as
we're not allocating a kore_buf, its contents and then memcpy()ing
that contents to a new netbuf.
2017-12-24 17:28:17 +01:00
Joris Vink fcc044af87 change all domain directives to * in examples. 2017-09-19 15:16:02 +02:00
Joris Vink 2eab2f1ed7 Revert "automatically resolve existing symbols upon reload."
This isn't ready yet.
2017-08-31 17:11:24 +02:00
Joris Vink ed4ef22f1b automatically resolve existing symbols upon reload.
doing this allows us to get rid of the validator reload
and handler reload as well as fixing websocket runtime
callbacks which were never being resolved upon module reloads.
2017-08-31 16:26:36 +02:00
Joris Vink f958d86616 remember the onload callback like we used too. 2017-08-30 15:11:07 +02:00
Joris Vink 03d5e4852b make sure FEATURES_INC hits kore.features. 2017-08-30 12:03:58 +02:00
Joris Vink 92b4225814 add memory tag example 2017-08-30 11:50:02 +02:00
Joris Vink 40c93e66a2 Add memory tagging.
This allows modules that have global pointers to upon reload repopulate
those with the addresses of when they were first created.

Meaning it now is easier to write modules that can be reloaded if those
modules kept global state one way or the other.

This should only be used at module init/reload time and is very simple:

if ((ptr = kore_mem_lookup(MY_ID_VALUE)) == NULL) {
	ptr = kore_malloc_tagged(length, MY_ID_VALUE);
	/* initialize for the first time. */
}

If we were in a reload the kore_mem_lookup() will return the original address
returned by the initial kore_malloc_tagged() call for MY_ID_VALUE.
2017-08-30 11:47:26 +02:00
Joris Vink 4893a030a6 small pgsql fixes.
- make sure conn_count per pgsqldb structure is initialized to 0.
- allow pgsql_conn_max to be 0, meaning just create a new connection
  if none was free.
2017-08-21 14:25:09 +02:00
Joris Vink ae4201c647 make r const 2017-08-08 09:11:41 +02:00
Joris Vink 6b60e4c6cc set nb to 0 2017-07-24 08:19:57 +02:00
Joris Vink fcc55453c7 massively simplify base64 encoding. 2017-07-24 08:19:03 +02:00
Joris Vink 8215277483 small pgsql fix.
if we fail at rolling back an in-error transaction on a connection
just remove that connection and go back to rescanning rather then
returning an error to the caller, there may be more functional
connections in the pipeline.
2017-07-13 11:02:41 +02:00
Joris Vink 3cea669a2c call pgsql_conn_cleanup() in case of an error in rollback. 2017-07-11 15:19:44 +02:00
Joris Vink 7f1a9b8092 Several postgresql improvements.
- Make pgsql_conn_count count per database rather then globally.
  This means you now define the number of clients *per* database registered
  rather then the number of clients in total of all databases.

- In case a connection is in failed transaction state Kore will now
  automatically rollback the transaction before placing that connection
  back in the connection pool.
2017-07-11 15:11:13 +02:00
Joris Vink 6415670753 set CONN_CLOSE_EMPTY for early HTTP errors.
while here fix missing connection response headers for errors.
2017-07-04 10:55:11 +02:00
Joris Vink 8e359ede13 flush out send buffer in http_error_response(). 2017-07-04 10:42:14 +02:00
Joris Vink 1465eb2982 slight change in wording 2017-06-28 10:20:14 +02:00
bhesmans a2d78179a4 Small fix in video stream example (#195) 2017-06-25 11:46:32 +02:00
Joris Vink 19b7f75b90 change up a comment that is wrong. 2017-06-01 10:10:54 +02:00
Joris Vink ae9694fb1d Fix build with libressl again.
LibreSSL defines OPENSSL_VERSION_NUMBER as 0x20000000L but does not have
the 1.1.0 API so we have to carefully check for LIBRESSL_VERSION_TEXT as
well before using that new API.
2017-05-27 11:57:46 +02:00
Joris Vink 584ef47c4f update README 2017-05-22 14:36:55 +02:00
Joris Vink 95daf3a62b Add support for openssl 1.1.0 release line.
Eventually I will phase out 1.0.2 down the line to get rid of the
nightmare that is the 2 different APIs.

This commit adds full support for building kore with 1.1.0e while
retaining the privsep keymanager support.

based on excellent work done by @hiwk.
2017-05-22 14:31:38 +02:00
Stanislav Yudin b73343aea4 add HTTP_METHOD_OPTIONS as another supported http method. (#186) 2017-04-04 09:37:19 +02:00
Joris Vink aed1a63c38 be more clear about openssl releases. 2017-03-30 09:40:13 +02:00
Joris Vink c545a922a1 Preserve the full host header under req->host.
Additionally make this header available via http_request_header().

prompted by #184
2017-03-30 09:38:23 +02:00
Joris Vink a3ed3bf7eb Convert pgsql-sync example after pgsql changes.
Only check if we bound something if we're asynchronous.
2017-03-24 13:00:05 +01:00
Joris Vink 59f7e85f45 Decouple pgsql from the http layer.
When the pgsql layer was introduced it was tightly coupled with the
http layer in order to make async work fluently.

The time has come to split these up and follow the same method we
used for tasks, allowing either http requests to be tied to a pgsql
data structure or a simple callback function.

This also reworks the internal queueing of pgsql requests until
connections to the db are available again.

The following API functions were changes:
	- kore_pgsql_query_init() -> kore_pgsql_setup()
		no longer takes an http_request parameter.
	- NEW kore_pgsql_init()
		must be called before operating on an kore_pgsql structure.
	- NEW kore_pgsql_bind_request()
		binds an http_request to a kore_pgsql data structure.
	- NEW kore_pgsql_bind_callback()
		binds a callback to a kore_pgsql data structure.

With all of this you can now build kore with PGSQL=1 NOHTTP=1.

The pgsql/ example has been updated to reflect these changes and
new features.
2017-03-24 12:53:07 +01:00
Joris Vink add6d724e3 expose connection address to python. 2017-03-24 12:42:40 +01:00
Joris Vink ed9a34ce95 cleanup net layer a bit.
this change was long overdue and finally gets rid of the legacy crap
we had laying around to appease openssl's read/write functions.
2017-03-16 09:54:46 +01:00
Joris Vink 3fdc1113c3 formatting 2017-03-15 09:24:29 +01:00
Joris Vink fb8035297d Allow workers to listen on different ports.
This commit allows worker processes to have individual listeners
not configured by the kore configuration.

If you do the following:
	- do not configure listeners in your .conf file
	- call kore_server_bind() in kore_worker_configure()

the workers will no longer fight over accept locks as the configured
ports no longer conflict with each other.

This allows me to create X amount of instances of a worker process that
are each individually accessible via unique ports.
2017-03-13 15:32:04 +01:00
Joris Vink 3b5d4a2b03 update example 2017-03-13 13:31:36 +01:00
Joris Vink ffbabed7d6 Move websocket_send() to pyconnection.
While here convert all instances of y* for incoming binary data to y#
since we won't be changing it at all and avoids some unneeded copying.
2017-03-13 13:30:57 +01:00
Joris Vink 4a56424842 Improve python websocket handling a bit.
Convert the data parameter to a string if the op was WEBSOCKET_OP_TEXT
or convert to bytes if op was WEBSOCKET_OP_BINARY so the callee does
not have to do this anymore.
2017-03-13 12:29:42 +01:00
Joris Vink 0b84a9c1d4 expose c.disconnect() and c.fd to Python. 2017-03-13 12:22:50 +01:00
Joris Vink af899f15e0 Set error if http_body_rewind() fails. 2017-03-13 11:19:58 +01:00
Joris Vink ec901d0339 Make http_body_rewind() public.
Also let this function reset offset and lengths for http_body_read().

Make sure of this function in the python code so req.body can be called
multiple times in succession.
2017-03-13 11:17:55 +01:00
Joris Vink 1f4aec43d9 toread is unsigned, it won't ever fall < 0. 2017-03-13 11:02:46 +01:00
Joris Vink 3ae9bb7ae9 change type of maxage. 2017-03-10 14:36:51 +01:00