Pages

Introduction to Quality of Service Classes(QoS)

        Quality of Service Classes(QoS) is an API with the help of which you can tell the Operating System what kind of work you are doing with what priority. This API is used in situation when you run out of CPU s to perform tasks and can't set priority of tasks i.e. in which order they will execute. Quality of Service Classes(QoS) are nothing more than flags which you will be feeding to dispatch objects to communicate to OS. Different four types of QoS are stated below:

1.) User Interactive(UI)
2.) User Initiative(IN)
3.) Utility(UT)
4.) Background(BG)

        Each of these classes performs different functionality and have a particular priority and are used for resource control to effectively execute your code. Resource control means managing CPU Scheduling, I/O priority, CPU throughput , CPU efficiency etc.
Brief Intro:

1.) User Interactive: This class relates and indicates User Interface i.e. something like user is interacting with for example: User is tapping a button or scrolling table view/collection view etc. The priority of this class is very high among all other classes. Simple example of how QoS apply to queues:

var UserInteractiveQueue: dispatch_queue_t {      //computed property will return queue with UI class
          return dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.value), 0)
}

2.) User Initiated: Or also termed as User Blocking means a task that does't required user interaction i.e. user can't continue to meaning progress with your application is indicate by this class. The priority of this class is Second high among all other classes.

var UserInitiativeQueue: dispatch_queue_t {      //computed property will return queue with IN class
          return dispatch_get_global_queue(Int(QOS_CLASS_USER_INITIATIVE.value), 0)
}

3.) Utility: If there is a long-running task that won't block user interaction but user can see the progress of that task, is indicated by Utility class i.e. Downloading task or in media player progress of song comes under Utility Class. The priority of this class is Second last among all other classes.

var UtilityQueue: dispatch_queue_t {      //computed property will return queue with UT class
          return dispatch_get_global_queue(Int(QOS_CLASS_UTILITY.value), 0)
}

4.) Background: For everything that user is not aware of kind of fetching some data from database or cleanup task etc. The priority of this class is last among all other classes.

var BackgroundQueue: dispatch_queue_t {      //computed property will return queue with BG class
          return dispatch_get_global_queue(Int(QOS_CLASS_BACKGROUND.value), 0)
}

        The above listed examples are of how you will be implementing QoS API with GCD API. There is a lot more of power you can achieve by applying this API with other GCD objects like GCD Blocks. In above examples we created some queues which all are concurrent and with QoS class specified  we made them work most efficiently according to priority of scheduling resources like CPU etc. 
        There is a lot more stuff with only this Multi threading environment, so stay tuned. 

1 comment:

Anonymous said...

some-comment-for-testing

Post a Comment