Tons of optimization of WriteChannel, WriteChannelWithServ, WriteCommon etc, dont call userrec::GetFullHost or snprintf for every item, call it just once.

Turns O(n) calls for every write into O(~1) calls per write.
Remove some debug from the socketengines which makes debugging hard on large channels (write availability message)


git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6171 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
brain 2006-12-30 15:11:40 +00:00
parent fce2d243c0
commit 6fff3c54be
5 changed files with 22 additions and 9 deletions

View File

@ -612,14 +612,17 @@ void chanrec::WriteChannel(userrec* user, char* text, ...)
void chanrec::WriteChannel(userrec* user, const std::string &text)
{
CUList *ulist = this->GetUsers();
char tb[MAXBUF];
if (!user)
return;
snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
if (IS_LOCAL(i->second))
user->WriteTo(i->second,text);
i->second->Write(std::string(tb));
}
}
@ -684,6 +687,7 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi
void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CUList &except_list, const std::string &text)
{
CUList *ulist;
char tb[MAXBUF];
switch (status)
{
@ -701,6 +705,8 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi
break;
}
snprintf(tb,MAXBUF,":%s %s",user->GetFullHost(),text.c_str());
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
if ((IS_LOCAL(i->second)) && (except_list.find(i->second) == except_list.end()))
@ -708,7 +714,7 @@ void chanrec::WriteAllExcept(userrec* user, bool serversource, char status, CULi
if (serversource)
i->second->WriteServ(text);
else
i->second->WriteFrom(user,text);
i->second->Write(std::string(tb));
}
}
}

View File

@ -129,7 +129,6 @@ int EPollEngine::DispatchEvents()
int i = epoll_wait(EngineHandle, events, MAX_DESCRIPTORS, 150);
for (int j = 0; j < i; j++)
{
ServerInstance->Log(DEBUG,"Handle %s event on fd %d",events[j].events & EPOLLOUT ? "write" : "read", events[j].data.fd);
if (events[j].events & EPOLLHUP)
{
ServerInstance->Log(DEBUG,"Handle error event on fd %d", events[j].data.fd);

View File

@ -137,7 +137,6 @@ int KQueueEngine::DispatchEvents()
int i = kevent(EngineHandle, NULL, 0, &ke_list[0], MAX_DESCRIPTORS, &ts);
for (int j = 0; j < i; j++)
{
ServerInstance->Log(DEBUG,"Handle %s event on fd %d",ke_list[j].flags & EVFILT_WRITE ? "write" : "read", ke_list[j].ident);
if (ke_list[j].flags & EV_EOF)
{
ServerInstance->Log(DEBUG,"kqueue: Error on FD %d", ke_list[j].ident);

View File

@ -146,7 +146,6 @@ int SelectEngine::DispatchEvents()
}
if (ev[i])
{
ServerInstance->Log(DEBUG,"Handle %s event on fd %d",writeable[ev[i]->GetFd()] || !ev[i]->Readable() ? "write" : "read", ev[i]->GetFd());
if (writeable[ev[i]->GetFd()])
{
if (ev[i])

View File

@ -1560,11 +1560,15 @@ void userrec::WriteCommon(const std::string &text)
try
{
bool sent_to_at_least_one = false;
char tb[MAXBUF];
if (this->registered != REG_ALL)
return;
uniq_id++;
/* We dont want to be doing this n times, just once */
snprintf(tb,MAXBUF,":%s %s",this->GetFullHost(),text.c_str());
for (UCListIter v = this->chans.begin(); v != this->chans.end(); v++)
{
@ -1574,7 +1578,7 @@ void userrec::WriteCommon(const std::string &text)
if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
already_sent[i->second->fd] = uniq_id;
i->second->WriteFrom(this, std::string(text));
i->second->Write(std::string(tb));
sent_to_at_least_one = true;
}
}
@ -1586,7 +1590,7 @@ void userrec::WriteCommon(const std::string &text)
*/
if (!sent_to_at_least_one)
{
this->WriteFrom(this,std::string(text));
this->WriteFrom(this,std::string(tb));
}
}
@ -1618,6 +1622,8 @@ void userrec::WriteCommonExcept(const std::string &text)
bool quit_munge = false;
char oper_quit[MAXBUF];
char textbuffer[MAXBUF];
char tb1[MAXBUF];
char tb2[MAXBUF];
strlcpy(textbuffer, text.c_str(), MAXBUF);
@ -1626,6 +1632,8 @@ void userrec::WriteCommonExcept(const std::string &text)
uniq_id++;
snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost(),textbuffer);
/* TODO: We need some form of WriteCommonExcept that will send two lines, one line to
* opers and the other line to non-opers, then all this hidebans and hidesplits gunk
* can go byebye.
@ -1648,6 +1656,7 @@ void userrec::WriteCommonExcept(const std::string &text)
strlcpy(oper_quit,textbuffer,MAXQUIT);
strlcpy(check,"*.net *.split",MAXQUIT);
quit_munge = true;
snprintf(tb2,MAXBUF,":%s %s",this->GetFullHost(),oper_quit);
}
}
}
@ -1661,6 +1670,7 @@ void userrec::WriteCommonExcept(const std::string &text)
strlcpy(oper_quit,textbuffer,MAXQUIT);
*check = 0; // We don't need to strlcpy, we just chop it from the :
quit_munge = true;
snprintf(tb2,MAXBUF,":%s %s",this->GetFullHost(),oper_quit);
}
}
@ -1675,9 +1685,9 @@ void userrec::WriteCommonExcept(const std::string &text)
{
already_sent[i->second->fd] = uniq_id;
if (quit_munge)
i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer));
i->second->Write(*i->second->oper ? std::string(tb2) : std::string(tb1));
else
i->second->WriteFrom(this, std::string(textbuffer));
i->second->Write(std::string(tb1));
}
}
}