Q:

delphi a good schema for high i/o usage

i have a program that uses 5 serial port for get data from hardware and save them in MySQL database and also transfer them to a third place with tcp/ip
for serial ports i use Async so the have separated threads.so thay cant make the system ui lagy.but if i use MySQL connection in threads created by serial port component it waste the time to read from buffer and make buffer over-load error
on the other hand if i send data process and MySQL store to an anonymous thread it cause a many working threads in queue...
what is best way to handle this kind of apps?

A:

Problem you have described is resolvable by setting FIFO Queue between COM ports and MySQL threads. There is some data flow (name it upstream) from COM devices, put this data to Thread-safe FIFO (Delphi has one implementation: System.Generics.Collections.TThreadedQueue) and allocate N threads for MySQL that will read data portion from FIFO Queue (name it downstream). So you convert you problem to classic Producer/Consumer task. If MySQL threads are too slow, FIFO size will grow, you have to grow number of MySQL threads in this case. You can detect optimal MySQL threads count by viewing FIFO avg size.
Problem of driver buffer over-load is caused in case when physical device write data more quickly than your program can process that data. In your case it happens due to slowness of MySQL thread part. 
Truth be told, COM port speed is very slow compared to CPU and Threads, I am sure core of your problem - you read from COM devices large count of little size data-pieces and wrap every one little data piece to SQL operation in background of your MySQL library. Shift your look to BATCHING - combine big count of low size datas to more large data batches, so you can decrease amount of SQL operations over TCP/IP

