Author: way0utwest

  • SQL Server 2008 R2

    The RTM date is out for SQL Server 2008 R2. At the UK Tech Days it was released as May 21 of this year, so my guess it’s pretty much done and there’s a little fit and finish work to be completed.

    I’m surprised that they can announce that date now. Wouldn’t it be done when it’s done? I’d think that you wouldn’t know what was done, what bugs were in, and when it’s completed until a week or so before. Aren’t final checks and tests needed? If something’s found, then wouldn’t, or shouldn’t that delay things?

    I’m not sure why we make a big deal of getting this done. If it RTM’d today, we could still have launch events over the next few months. It isn’t like anyone is really going to stand in line at a store to buy it and deploy it today.

    RTM it when it’s done, throw a party for the development/test groups, and then let us get it when we can. We’ll appreciate that more.

  • It’s a Start

    One of my 2010 goals is to really increase my SSRS knowledge. I’ve used SSRS in a cursory manner over the years, but never really delved into building complex reports and trying new things. So I decided to fix that and work my way through some articles and books on the product.

    SSRS1

    A new VM, setup just for this, lives. It’s in place and ready for me to begin building reports and growing knowledge.

    Now I just need a good db with some interesting stats 😉

  • Should I Go? SQL Saturday plans for the year.

    There have been quite a few more SQL Saturday announcements this week for new cities. I enjoy attending these events, and look forward to going when I can. I have plans to go to Baton Rouge (#28) in August and Pensacola (#22) in June, after having wonderful times in those cities last year.

    It’s been a rough year for traveling, and while my wife is usually home on the weekends, she’s been gone quite a bit during the weeks. So I’m not thrilled about traveling too much more. Phoenix (#47) is tempting, though July means no skiing around there :). I like the city, and it’s a short flight. I could likely even get back late Sat night or early Sun morning in time for my Sun baseball games. I don’t have a baseball time yet, so I’m hesitant to book that one.

    I would like to support Louisville (#45) as well. I cancelled last year when some other things came up, and I’d like to go back. My sister-in-law lives there, so that would be a good chance to catch up with her and her fiancé for the weekend. That one is tempting, though I don’t want to get into a heavy travel fall. I’ll likely have Connections and PASS in November, and I semi-committed to get back to Orlando for their SQL Saturday event. I’d have to choose between Louisville and Raleigh (#46), however as I won’t travel two weekends in a row.

    Then there are the user groups. I haven’t made any meetings this year, mainly because of heavy travel in the family. I have been trying to schedule a meeting for the Utah groups, and Jason Brimhall extended a Las Vegas invitation as well. Those are quick trips, but I just haven’t made the commitment yet. Utah will have to wait until next ski season, but Las Vegas may be in the cards if the travel schedule eases up in the next couple of months.

    I do like to support the community, and Red Gate does a great job of supporting me, and Brad McGehee, as we speak at various functions. Hopefully I’ll get to a few more events this year, and maybe try out a few new cities, like Dallas, NYC, and Portland in 2011 as I’m sure they’ll schedule new SQL Saturdays.

  • A Quick Queue Process

    As SQLServerCentral grew, we evolved through a few email sending solutions to meet the demand. We started with a manual process, then went to a homegrown automated one, then moved through 2 purchased software solutions before coming back to a (new) homegrown one.

    When we used to try and send 100,000 emails a night, scale became an issue. We had to complete the sending overnight so that when the load on the servers increased during the US workday, we would not be overloaded. However we also had to ensure that we didn’t mail multiple times to a person, so we had to build a solid, stable, reliable system.

    We chose to implement email as a Queue system using a database table. This was prior to SQL Server 2005, though I’m not sure we would have used Service Broker if it had been later.

    We stored all emails in a table like this:

    create table Emails(

    mailingid int identity(1,1),

    datecreated datetime,

    datesent datetime,

    emailid int,

    priority tinyint

    recipient varchar(200),

    sender varchar(50)

    )

    We would load this table with 100,000+ rows, one for each person receiving the email. We stored the actual email text in another table and joined on emailid to get that data.

    Our sending process had a series of client machines that would query this table for a batch of rows, send a mail to each one, and then update this table. We built this for scalability as we could easily (and cheaply) add new client machines for sending mail. Now we just needed to handle concurrency issues.

    Our first idea was to read the table, update some records, and repeat. So we’d do this

    select top 100

    emailid, recipient

    from emails

    where sender is null

    and dateSent is null

    set rowcount 100

    update emails

    set sender = ‘Client1’

    where sender is null

    and dateSent is null

    set rowcount 0

    — processing on the client here

    update emails

    set datesent = getdate()

    where emailid = x

    This assumes that Client1 was connecting. Client2 would use that name in the update.

    If you read this and have any experience with T-SQL, you’d quickly realize there’s an issue here. Between the SELECT and the UPDATE, another client could read those same rows. So we enclosed it in a transaction, which means you could UDDATE then SELECT, or reverse that.

    However that causes a concurrency issue. With 2 clients it took a little time, but we did some testing and found that there was repeated blocking. That wasn’t an issue at the time, but it could easily have become a bigger issue as we added more machines and increased the volume of sending.

    So we went back to the drawing board and came up with a new approach.

    We changed our code to this:

    set rowcount 100

    update emails

    set sender = ‘Client1’

    where sender is null

    and dateSent is null

    set rowcount 0

    select

    emailid, recipient

    from emails

    where sender =’Client1’

    and dateSent is null

    Not much different but two significant changes in the SELECT. First, but doing the update, we essentially removed those 100 rows from the queue. The update is quick, and as soon as it’s finished the next machines can begin reading their own rows. SQL Server provides the locking which prevents any machine from overwriting any other machine’s rows, so the “marking” of them by name keeps them from being updated again.

    The SELECT statement is now quicker, since the number of rows scanned is small. We index those fields, and the number set to the sender is low, so this is a less resource intensive query.

    Note that I’m not sure if we’re doing things the same way now. When Red Gate bought the site, they took over development and I know they kept some pieces of this, but potentially they upgraded or changed some of this process. However for the 7 years I ran the site and worked on it’s development, this proved to be the best solution for us.

    Recently there was also an article on SQLServerCentral on dealing with queues that takes a slightly different approach.