1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

CMS integration with XF, very slow to update thread

Discussion in 'XenForo Development Discussions' started by Julio Franco, Jan 30, 2014.

  1. Julio Franco

    Julio Franco Member

    Hello guys,

    Since we moved to Xenforo over 2 years ago, we've had a full in-house CMS integration between our news comments and Xenforo threads. We love your software and it was the step in the right direction coming from awful vBulletin.

    Recently we've struggled with a very slow XF function when we call it from our CMS (see details below). I was hoping to get your assistance.

    When we update a news story (and thus send the necessary changes to the respective forum thread), we use the following:

            $threadWriter XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $threadWriter->setExistingData$threadId );
    $title )
    $date )
    $threadWriter->set('post_date'$date );
    $threadWriter->set('last_post_date'$date );
    Seems simple enough, but instead of taking milliseconds it's delayed anything between 1-4 seconds.
    Otherwise most of XF is very fast or instant in our server. Any idea what could be the culprit?
  2. LPH

    LPH Well-Known Member

    Can you use getModelFromCache to pull the $threadId?
  3. tenants

    tenants Well-Known Member

    Nothing there should cause that sort of delay.

    How big is your board, how long does it take to create a thread manually?

    If this works (I think it should) can you literally dump a time stamp out before and after this bit of code to make sure it is this causing the delay:

    $threadWriter = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
    $threadWriter->setExistingData( $threadId );
    if($title)$threadWriter->set('title', $title);
       $threadWriter->set('post_date', $date );
       $threadWriter->set('last_post_date', $date );
    It sounds to me that you might be calling it over and over, instead of just once... but I can't see the rest of code

    ... dumping the time stamp every time you call this code should tell you that (if you see more than 2 timestamps... there in lies your issue ;) )
    Last edited: Jan 30, 2014
    Rob likes this.
  4. Julio Franco

    Julio Franco Member

    Thank you for your responses. We haven't been sitting duck on them but actually testing over and over to find the source of the slowdown which is still ongoing.

    After placing timestamps in each of the processes performed for updating a news story (and consequently updating Xenforo's thread), we've discarded the possibility of duplicated calls as was hinted before. However, we've discovered that the issue lies in the post update (not the thread):

    We've narrowed down the slowdown to the last line "$writer->save();", in the best of cases it takes a full 3 seconds to update, and in the worst up to 6 seconds which feels like an eternity.

    For comparison, we performed several tests updating a post directly in the forum and in the worst of scenarios it takes 2 seconds.

    As side information, we currently have:
    182,619 threads
    1,330,719 posts

    Thanks again for your kind help!
  5. tenants

    tenants Well-Known Member

    2 seconds to create a normal thread might just be the source of your issue (even if that is the worse case)

    Here it's less than 1 second (but that's with 688,812 posts). I think you might be in the domain of tweaking your server/mysql to perform better at creating threads for large forums.
    That's out of my knowledge domain

    However, there seems to be nothing wrong with the way you are creating the thread, this is similar to how the core does it (unless there is an issue with large forums and using the datawriter via plugins... that could be a possibility, and could be investigated, but I've never come across this).

    When editing an existing thread you POST form data to index.php?threads/threadname.x/save
    So, looking at the XenForo_ControllerPublic_Thread::actionSave() function, you will see:

      $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
      $dw->setExtraData(XenForo_DataWriter_Discussion_Thread::DATA_FORUM, $forum);
    (see file library/XenForo/ControllerPublic/Thread.php line 943)

    So as far as I can see, you are doing it "correctly".

    When in doubt, I usually look to the core
    I can't really see the difference between yours and the core

    You both use the Datawritter: XenForo_DataWriter_Discussion_Thread
    You both set setExistingData and other columns, and then call the datawritter save();

    So, I think you need to look at the 2 second issue of saving a thread... Server/MySQL performance is not really my area, but there are quite a few threads about it:

    Possibly @Slavik might be able to tell you more about performance tweaks, or even recommend servers
    Last edited: Feb 5, 2014
    LPH likes this.
  6. Slavik

    Slavik XenForo Moderator Staff Member

    Sounds like you need to debug the source of your slow thread posting. Is it equally as slow with everything disabled except the bare xenforo install?
  7. LPH

    LPH Well-Known Member

    I just wanted to add a little bit of information to this thread.

    Adding posts externally to the forums with the same code worked well in previous version, including XenForo 1.3 beta 1. But something changed in Beta 2 and now the writing takes 10 plus seconds. The writing used to be a blink of an eye.
  8. oO5 Dynasty

    oO5 Dynasty Active Member

    what does debug do and how do you use it to detect problems?

Share This Page