27 Commits

Author SHA1 Message Date
Markus Mäkelä
895d950da0 Format all source files with Astyle
Formatted all source files Astyle.
2017-09-28 07:04:21 +03:00
Johan Wikman
8414ce6e80 MXS-1392 Re-introduce zombie queue
- Extend Worker interface so that zombies can be registered
- Call deletion function at the end of event loop
2017-09-08 12:41:41 +03:00
Johan Wikman
49ba1f8fa0 MXS-1360 Add 'thread_stack_size' configuration value
Using the 'thread_stack_size' configuration value, the stack size
of the worker threads can be adjusted.
2017-08-14 15:31:00 +03:00
Johan Wikman
f546a17e77 Update change date of 2.2 2017-06-01 10:24:20 +03:00
Esa Korhonen
dbfd631fed Change session registry to a template class
The template class wraps a HashMap such that only a few operations
are allowed. Usage requires specializing a RegistryTraits class
template for each entry type.
2017-05-19 10:16:37 +03:00
Markus Mäkelä
0e57bec4ef MXS-1220: Add threads resource
The threads are now a REST API resource exposed via the /maxscale/threads
resource collection.
2017-05-09 15:32:42 +03:00
Esa Korhonen
ee20191645 KILL [CONNECTION | QUERY] support, part2B
Various small changes to part2, as suggested by comments and otherwise.
Mostly renaming, working logic should not change.

Exception: session id changed to 64bit in the container and associated
functions. Another commit will change it to 64bit in the session itself.
2017-05-08 09:58:02 +03:00
Esa Korhonen
17f6e94cba KILL [CONNECTION | QUERY] support, part2
MySQL sessions are added to a hasmap when created, removed when closed.
MYSQL_COM_PROCESS_KILL is now detected, the thread_id is read and the kill
command sent to all worker threads to find the correct session. If found, a
fake hangup even is created for the client dcb.

As is, this function is of little use since the client could just disconnect
itself instead. Later on, additional commands of this nature will be  added.
2017-05-08 09:51:07 +03:00
Johan Wikman
f66620c89c Accept auto_ptr<T> where T is derived type
Without the member template it is not possible to pass an auto_ptr
instantiated with a derived type to post() or broadcast().

The reason is that the conversion constructor and conversion
operator of auto_ptr are equally good for that purpose, and hence
the compilation ends with an error.
2017-05-08 09:36:16 +03:00
Markus Mäkelä
dd8a10f466 Remove old polling message system
The old polling message system is obsolete now that the worker messages
are implemented. The old system was only used to clean up the persistent
connection pool of a server.
2017-05-03 14:16:35 +03:00
Markus Mäkelä
4c6e0c75a5 Allow execution of tasks from within worker threads
It is now possible to define whether tasks are executed immediately or put
on the event queue of the worker thread. If task execution is in automatic
mode and the current executing thread is a worker thread, the
Task->execute method is called immediately.

This allows tasks to be posted from within worker threads. This is
intended to be used when purging of stale persistent connections and
printing diagnostic output via MaxAdmin. All of these actions are done
from within a worker thread.
2017-05-03 14:03:23 +03:00
Johan Wikman
00b6c10089 Adjust Worker terminology
- Posting a task to a worker for execution (without implicit wait)
  is called "post".
- Posting a task to every worker for execution (without implicit wait)
  is called "broadcast".

In these cases the task must be provided as a pointer or auto_ptr, to
indicate that the provided pointer must remain alive for longer than
the duration of the function call.

- Posting a task to a worker for execution *and* waiting for all workers
  to have executed the task is called "execute" and the two variants are
  now called "execute_concurrently" and "execute_serially".

In these cases the task is provided as a reference, since the functions
will return only when all workers have (in concurrent or serial fashion)
executed the task. That is, it need not remain alive for longer than the
duration of the function call.
2017-05-02 11:32:08 +03:00
Johan Wikman
1b58a75f42 Add concurrent execution helper to Worker
Concurrently executing a task on all workers *and* waiting until
all workers have executed the task seems to be common enough to
warrant a helper function for that purpose.
2017-05-02 10:54:29 +03:00
Esa Korhonen
bfd94c2b31 KILL [CONNECTION | QUERY] support, part1
Preparation for adding KILL syntax support.
Session id changed to uint32 everywhere. Added atomic op.
Session id can be acquired before session_alloc().
Added session_alloc_with_id(), which is given a session id number.
Worker object has a session_id->SESSION* mapping, not used yet.
2017-05-02 10:29:55 +03:00
Markus Mäkelä
963ff0216d Allow serial execution of worker tasks
The Worker::execute_on_all_wait is intended to be used with dcb_foreach
which expects a single-threaded context for its function.
2017-04-25 15:04:42 +03:00
Johan Wikman
8174690f77 Introduce concept of Worker tasks
A Worker::Task is an object that can be sent to a worker for
execution. The task is sent to the worker using the messaging
mechanism where the `execute` function of the task will be
called in the thread context of the worker.

There are two kinds of tasks; regular tasks and disposable tasks.
The former are just sent to the worker for execution while the
latter are sent and subsequently disposed of, once the task has
been executed.

A disposable task can be sent to either one worker or to all
workers. In the latter case, the task will be deleted once it
has been executed by all workers.

A semaphore can be associated with a regular task. Once the task
has been executed by the worker, the semaphore will automatically
be posted. That way, it is trivial to send a task for execution
to a worker and wait until the task has been executed. For instance:

    Semaphore sem;
    MyTask task;

    pWorker->execute(&task, &sem);
    sem.wait();

    const MyResult& result = task.result();

The low level mechanism for posting and broadcasting messages will
be removed.
2017-04-24 14:52:54 +03:00
Johan Wikman
56b411aea9 Add shared epoll instance to workers
All workers share an epoll instance that is added level-triggered
to the epoll instance of each Worker. This is intended to be used
together with listening sockets.

When a listening socket is added to the shared epoll instance the
effect is that EPOLLIN will be active for it whenever there is a
connection pending on a listening socket added to that epoll
instance.

When that occurs all workers in their epoll_wait()-calls will return.
When the workers subsequently call epoll_wait() on the shared epoll
instance, that will return with an event provided some other thread(s)
has not yet called accept() on the listening socket.

As each worker extracts just one event at a time and calls accept just
once before calling epoll_wait(), it means that the client connections
will be distributed evenly across all workers, provided the load on
the workers is roughly the same. If it isn't then a worker with less
load will get more connections to handle (which will even out the load).
2017-04-21 21:24:20 +03:00
Johan Wikman
a27bec5e88 Add return value to Worker::init()
Cleaner to return status than exit upon failure.
2017-04-21 19:57:45 +03:00
Johan Wikman
db3153ee4e Move statistics to Worker
Now the statistics is in a single structure and the property of the
Worker instance in question. Methods are provided for obtaining the
statistics of all workers in one go.
2017-04-20 13:51:16 +03:00
Johan Wikman
722d6da46f The thread state is now a property of the worker
A worker's state is not statistics, but transient information.
2017-04-20 13:51:16 +03:00
Johan Wikman
effa2f5674 poll_waitevents moved to Worker
A direct move without any non-essential modifications. Poll_waitevents will
be turned into a regular methods using instance variables.
2017-04-20 13:51:16 +03:00
Johan Wikman
3ac619bfec Fold thread state into poll stats 2017-04-20 13:51:16 +03:00
Johan Wikman
f952a11eb8 Move queue statistics to Worker
Just like the thread stats and poll stats earlier, the queue stats
are now moved to worker.

A litte refactoring still, and the polling will only work on local
data.
2017-04-20 13:51:16 +03:00
Johan Wikman
76825eb2c5 Poll statistics moved to worker
Each worker now has a separate structure for collecting the
polling statistics that is passed to epoll_waitevents(). When
the stats are asked for, we loop over all separate stats and
combine them. So, instead of having every statistics of each
thread one cacheline apart, each thread has all its statistics
in one lump that, for obvious reasons, are going to be apart.

The primary purpose of this excersize is to remove the hardwired
nature of the statistics collection. For instance, the admin
thread will be doing I/O but that I/O should not be included
in the statistics of the workers.
2017-04-20 13:51:16 +03:00
Johan Wikman
c11ca1c328 Move thread data to workers
This is a step in the direction that any worker/thread related data
is the property of the worker/thread.
2017-04-20 13:51:16 +03:00
Johan Wikman
052975bccd Add MessageQueue to Worker
The Worker no longer creates a pipe and implements the cross
worker/thread message mechanism itself. Instead it has a
MessageQueue instance variable for that purpose.
2017-04-20 13:51:16 +03:00
Johan Wikman
9829d6e365 Add epoll instance to Worker
And add the Worker header...
The epoll instance is not used yet, but the common creation of epoll
instances in poll.cc will be removed and the epoll instances of each
worker used instead.
2017-04-20 13:51:16 +03:00