diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-29 00:19:35 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-12-29 00:19:35 +0000 |
commit | 0bf908e49c957ce35ac194a0c9b739f22d76182e (patch) | |
tree | 839be4613f600d34ff5c3285ba3f5840aac24b11 /src | |
parent | bbad4e536234949a1ce480e6c6f901c884621c5e (diff) |
Optimizing to not use so much cpu with high user loads
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2691 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/dnsqueue.cpp | 3 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 11 | ||||
-rw-r--r-- | src/inspircd.cpp | 18 | ||||
-rw-r--r-- | src/socketengine.cpp | 45 |
4 files changed, 44 insertions, 33 deletions
diff --git a/src/dnsqueue.cpp b/src/dnsqueue.cpp index 3b6bd2103..c0f516e74 100644 --- a/src/dnsqueue.cpp +++ b/src/dnsqueue.cpp @@ -264,6 +264,7 @@ void dns_poll(int fdcheck) * just to be safe so we dont get any more events * about it. */ - SE->DelFd(fdcheck); + if (SE) + SE->DelFd(fdcheck); } diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 71840a22a..57f81a044 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -1093,11 +1093,16 @@ void ShowRULES(userrec *user) // registration timeout maximum seconds) bool AllModulesReportReady(userrec* user) { + if (!Config->global_implementation[I_OnCheckReady]) + return true; for (int i = 0; i <= MODCOUNT; i++) { - int res = modules[i]->OnCheckReady(user); - if (!res) - return false; + if (Config->implement_lists[i][I_OnCheckReady]) + { + int res = modules[i]->OnCheckReady(user); + if (!res) + return false; + } } return true; } diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 6d21e3677..993348aff 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -410,7 +410,7 @@ bool InspIRCd::LoadModule(const char* filename) int InspIRCd::Run() { bool expire_run = false; - std::vector<int> activefds; + int activefds[65535]; int incomingSockfd; int in_port; userrec* cu = NULL; @@ -462,19 +462,26 @@ int InspIRCd::Run() expire_run = true; continue; } - if ((TIME % 8) == 1) + else if ((TIME % 8) == 1) + { expire_run = false; + } /* Once a second, do the background processing */ - if (TIME != OLDTIME) - while (DoBackgroundUserStuff(TIME)); + if ((TIME != OLDTIME) && ((TIME % 2) == 0)) + DoBackgroundUserStuff(TIME); /* Call the socket engine to wait on the active * file descriptors. The socket engine has everything's * descriptors in its list... dns, modules, users, * servers... so its nice and easy, just one call. */ - SE->Wait(activefds); + numberactive = SE->Wait(activefds); + + if (!numberactive) + continue; + + log(DEBUG,"%d active fds this time around",numberactive); /** * Now process each of the fd's. For users, we have a fast @@ -483,7 +490,6 @@ int InspIRCd::Run() * listening ports or module sockets though, things could get * ugly. */ - numberactive = activefds.size(); for (unsigned int activefd = 0; activefd < numberactive; activefd++) { int socket_type = SE->GetType(activefds[activefd]); diff --git a/src/socketengine.cpp b/src/socketengine.cpp index 82e79ece3..f910802bb 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -66,7 +66,9 @@ bool SocketEngine::AddFd(int fd, bool readable, char type) { if ((fd < 0) || (fd > 65535)) return false; - this->fds.push_back(fd); +#ifdef USE_SELECT + fds[fd] = fd; +#endif ref[fd] = type; if (readable) { @@ -107,17 +109,14 @@ bool SocketEngine::DelFd(int fd) if ((fd < 0) || (fd > 65535)) return false; - bool found = false; - for (std::vector<int>::iterator i = fds.begin(); i != fds.end(); i++) +#ifdef USE_SELECT + std::map<int,int>::iterator t = fds.find(fd); + if (t != fds.end()) { - if (*i == fd) - { - fds.erase(i); - log(DEBUG,"Deleted fd %d",fd); - found = true; - break; - } + fds.erase(t); + log(DEBUG,"Deleted fd %d",fd); } +#endif #ifdef USE_KQUEUE struct kevent ke; EV_SET(&ke, fd, ref[fd] & X_READBIT ? EVFILT_READ : EVFILT_WRITE, EV_DELETE, 0, 0, NULL); @@ -140,26 +139,26 @@ bool SocketEngine::DelFd(int fd) } #endif ref[fd] = 0; - return found; + return true; } -bool SocketEngine::Wait(std::vector<int> &fdlist) +int SocketEngine::Wait(int* fdlist) { - fdlist.clear(); + int result = 0; #ifdef USE_SELECT FD_ZERO(&wfdset); FD_ZERO(&rfdset); timeval tval; int sresult; - for (unsigned int a = 0; a < fds.size(); a++) + for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++) { - if (ref[fds[a]] & X_READBIT) + if (ref[a->second] & X_READBIT) { - FD_SET (fds[a], &rfdset); + FD_SET (a->second, &rfdset); } else { - FD_SET (fds[a], &wfdset); + FD_SET (a->second, &wfdset); } } @@ -168,10 +167,10 @@ bool SocketEngine::Wait(std::vector<int> &fdlist) sresult = select(FD_SETSIZE, &rfdset, &wfdset, NULL, &tval); if (sresult > 0) { - for (unsigned int a = 0; a < fds.size(); a++) + for (std::map<int,int>::iterator a = fds.begin(); a != fds.end(); a++) { - if ((FD_ISSET (fds[a], &rfdset)) || (FD_ISSET (fds[a], &wfdset))) - fdlist.push_back(fds[a]); + if ((FD_ISSET (a->second, &rfdset)) || (FD_ISSET (a->second, &wfdset))) + fdlist[result++] = a->second; } } #endif @@ -180,14 +179,14 @@ bool SocketEngine::Wait(std::vector<int> &fdlist) ts.tv_sec = 0; int i = kevent(EngineHandle, NULL, 0, &ke_list[0], 65535, &ts); for (int j = 0; j < i; j++) - fdlist.push_back(ke_list[j].ident); + fdlist[result++] = ke_list[j].ident; #endif #ifdef USE_EPOLL int i = epoll_wait(EngineHandle, events, 65535, 100); for (int j = 0; j < i; j++) - fdlist.push_back(events[j].data.fd); + fdlist[result++] = events[j].data.fd; #endif - return true; + return result; } std::string SocketEngine::GetName() |