@@ -67,7 +67,22 @@ class db_cmd_t
6767
6868struct db_cmd_copy_t : public db_cmd_t
6969{
70- enum { Max_buf_size = 10 * 1024 * 1024 };
70+ enum {
71+ /* * Size of a single buffer with COPY data for Postgresql.
72+ * This is a trade-off between memory usage and sending large chunks
73+ * to speed up processing. Currently a one-size fits all value.
74+ * Needs more testing and individual values per queue.
75+ */
76+ Max_buf_size = 10 * 1024 * 1024 ,
77+ /* * Maximum length of the queue with COPY data.
78+ * In the usual case, PostgreSQL should be faster processing the
79+ * data than it can be produced and there should only be one element
80+ * in the queue. If PostgreSQL is slower, then the queue will always
81+ * be full and it is better to keep the queue smaller to reduce memory
82+ * usage. Current value is just assumed to be a reasonable trade off.
83+ */
84+ Max_buffers = 10
85+ };
7186 // / Name of the target table for the copy operation
7287 std::shared_ptr<db_target_descr_t > target;
7388 // / Vector with object to delete before copying
@@ -141,6 +156,7 @@ class db_copy_thread_t
141156 std::thread m_worker;
142157 std::mutex m_queue_mutex;
143158 std::condition_variable m_queue_cond;
159+ std::condition_variable m_queue_full_cond;
144160 std::deque<std::unique_ptr<db_cmd_t >> m_worker_queue;
145161
146162 // Target for copy operation currently ongoing.
0 commit comments