diff --git a/.gitignore b/.gitignore index ca216a6d6..e6af4ccae 100644 --- a/.gitignore +++ b/.gitignore @@ -101,3 +101,6 @@ deps/protobuf/protobuf-2.6.1/ test/.vagrant .DS_Store proxysql-tests.ini + +#heaptrack +heaptrack.* diff --git a/lib/MySQL_Protocol.cpp b/lib/MySQL_Protocol.cpp index ef9decbc3..467dcc062 100644 --- a/lib/MySQL_Protocol.cpp +++ b/lib/MySQL_Protocol.cpp @@ -1535,6 +1535,9 @@ bool MySQL_ResultSet::get_resultset(PtrSizeArray *PSarrayFinal) { void MySQL_ResultSet::buffer_to_PSarrayOut() { if (buffer_used==0) return; // exit immediately if the buffer is empty + if (buffer_used < RESULTSET_BUFLEN/2) { + buffer=(unsigned char *)realloc(buffer,buffer_used); + } PSarrayOUT->add(buffer,buffer_used); buffer=(unsigned char *)malloc(RESULTSET_BUFLEN); buffer_used=0; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index cff4610c4..4bc0ce791 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -319,7 +319,29 @@ void MySQL_Session::writeout() { //if (server_myds) server_myds->set_pollout(); if (client_myds) { if (mirror==false) { - client_myds->write_to_net_poll(); + bool runloop=false; + int retbytes=client_myds->write_to_net_poll(); + if (retbytes==QUEUE_T_DEFAULT_SIZE) { // optimization to solve memory bloat + runloop=true; + } + while (runloop) { + runloop=false; // the default + client_myds->array2buffer_full(); + //nfds_t nfds=1; + struct pollfd fds; + fds.fd=client_myds->fd; + fds.events=POLLOUT; + fds.revents=0; + int retpoll=poll(&fds, 1, 0); + if (retpoll>0) { + if (fds.revents==POLLOUT) { + retbytes=client_myds->write_to_net_poll(); + if (retbytes==QUEUE_T_DEFAULT_SIZE) { // optimization to solve memory bloat + runloop=true; + } + } + } + } } } //if (server_myds && server_myds->net_failure==false) server_myds->write_to_net_poll(); diff --git a/src/Makefile b/src/Makefile index 846f989a8..ab6587fc6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -56,7 +56,8 @@ LDIRS=-L$(LDIR) -L$(JEMALLOC_LDIR) $(LIBCONFIG_LDIR) -L$(RE2_PATH)/obj -L$(LIBEV MYCPPFLAGS=-std=c++11 $(IDIRS) $(OPTZ) $(DEBUG) LDFLAGS+= #LIBS=-rdynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -linjection -levent -lmariadbclient -lprotobuf -Wl,-Bdynamic -lpthread -lm -lz -lrt -ldl -lcrypto -lssl $(EXTRALINK) -MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) +#MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -ljemalloc -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) +MYLIBS=-Wl,--export-dynamic -Wl,-Bstatic -lconfig -lproxysql -ldaemon -lconfig++ -lre2 -levent -lmariadbclient -Wl,-Bdynamic -lpthread -lm -lz -lrt -lcrypto -lssl $(EXTRALINK) #LIBS=-rdynamic -Wl,-Bstatic -lproxysql -ljemalloc -levent $(GLIB_LIB) -Wl,-Bdynamic -ldl -lpthread -lm -lz -lrt UNAME_S := $(shell uname -s) diff --git a/src/main.cpp b/src/main.cpp index 3a0952da5..6399df8c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -126,7 +126,7 @@ static volatile int load_; //__thread l_sfp *__thr_sfp=NULL; -const char *malloc_conf = "xmalloc:true,lg_tcache_max:16"; +const char *malloc_conf = "xmalloc:true,lg_tcache_max:16,purge:decay_time"; //const char *malloc_conf = "prof_leak:true,lg_prof_sample:0,prof_final:true,xmalloc:true,lg_tcache_max:16"; int listen_fd;