Setting Thread Affinity in Ultra Messaging Applications

Similar documents
Informatica Ultra Messaging Streaming Edition Version Release Notes June Contents. New Features and Enhancements.

CS420: Operating Systems

Processes and Threads

PowerExchange for Facebook: How to Configure Open Authentication using the OAuth Utility

Chapter 5: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads

Agenda. Threads. Single and Multi-threaded Processes. What is Thread. CSCI 444/544 Operating Systems Fall 2008

Chapter 4: Multithreaded Programming. Operating System Concepts 8 th Edition,

CS 3305 Intro to Threads. Lecture 6

Low latency & Mechanical Sympathy: Issues and solutions

Thread Concept. Thread. No. 3. Multiple single-threaded Process. One single-threaded Process. Process vs. Thread. One multi-threaded Process

Lecture 2 Process Management

Chapter 5: Processes & Process Concept. Objectives. Process Concept Process Scheduling Operations on Processes. Communication in Client-Server Systems

Using Synchronization in Profiling

Chapter 4: Threads. Overview Multithreading Models Threading Issues Pthreads Windows XP Threads Linux Threads Java Threads. Operating System Concepts

Threads. studykorner.org

4. Concurrency via Threads

Lesson 6 Programming Arduino Example 9.7. Chapter-9 L06: "Internet of Things ", Raj Kamal, Publs.: McGraw-Hill Education

Chapter 4: Multithreaded

CS 450 Operating System Week 4 Lecture Notes

Threads. What is a thread? Motivation. Single and Multithreaded Processes. Benefits

Informatica Migration Guide for TIBCO Rendezvous

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Processes and threads

Chapter 4: Threads. Chapter 4: Threads

Threads. Thread Concept Multithreading Models User & Kernel Threads Pthreads Threads in Solaris, Linux, Windows. 2/13/11 CSE325 - Threads 1

Outline. Threads. Single and Multithreaded Processes. Benefits of Threads. Eike Ritter 1. Modified: October 16, 2012

I. INTRODUCTION FACTORS RELATED TO PERFORMANCE ANALYSIS

From Processes to Threads

Creating OData Custom Composite Keys

I.-C. Lin, Assistant Professor. Textbook: Operating System Concepts 8ed CHAPTER 4: MULTITHREADED PROGRAMMING

Multithreaded Programming

Chapter 4: Multi-Threaded Programming

Chapter 4: Multithreaded Programming

Chapter 4 Multithreaded Programming

Quiz: Simple Sol Threading Model. Pthread: API and Examples Synchronization API of Pthread IPC. User, kernel and hardware. Pipe, mailbox,.

For use by students enrolled in #71251 CSE430 Fall 2012 at Arizona State University. Do not use if not enrolled.

Chapter 4: Threads. Operating System Concepts with Java 8 th Edition

OPERATING SYSTEM. Chapter 4: Threads

Dynamic Data Masking: Capturing the SET QUOTED_IDENTIFER Value in a Microsoft SQL Server or Sybase Database

CS 5523 Operating Systems: Midterm II - reivew Instructor: Dr. Tongping Liu Department Computer Science The University of Texas at San Antonio

Chapter 4: Multithreaded Programming

CSI3131 Final Exam Review

A Predictable RTOS. Mantis Cheng Department of Computer Science University of Victoria

RTI Distributed Logger Getting Started Guide

WebSphere MQ Low Latency Messaging V2.1. High Throughput and Low Latency to Maximize Business Responsiveness IBM Corporation

Agenda Process Concept Process Scheduling Operations on Processes Interprocess Communication 3.2

Chapter 3: Processes. Operating System Concepts 8th Edition

Che-Wei Chang Department of Computer Science and Information Engineering, Chang Gung University

Chapter 4: Threads. Chapter 4: Threads

Configuring a JDBC Resource for IBM DB2/ iseries in Metadata Manager HotFix 2

Threads. CS3026 Operating Systems Lecture 06

CS307: Operating Systems

Creating an Avro to Relational Data Processor Transformation

Resource Containers: A New Facility for Resource Management in Server Systems

Last class: Today: Thread Background. Thread Systems

Chapter 4: Threads. Chapter 4: Threads. Overview Multicore Programming Multithreading Models Thread Libraries Implicit Threading Threading Issues

Code Page Configuration in PowerCenter

CSE 4/521 Introduction to Operating Systems

Threads. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Chapter 4: Threads. Operating System Concepts 9 th Edition

Operating System. Chapter 4. Threads. Lynn Choi School of Electrical Engineering

CPU Scheduling (Part II)

Interoperation of tasks

SMD149 - Operating Systems

Chapter 4: Multithreaded Programming

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Operating Systems: Internals and Design Principles. Chapter 4 Threads Seventh Edition By William Stallings

Chapter 4: Multithreaded Programming

CSCE 313: Intro to Computer Systems

Processes, Threads and Processors

CHAPTER 3 - PROCESS CONCEPT

Last Class: CPU Scheduling. Pre-emptive versus non-preemptive schedulers Goals for Scheduling: CS377: Operating Systems.

Chapter 4: Threads. Operating System Concepts. Silberschatz, Galvin and Gagne

Optimizing Performance for Partitioned Mappings

Chapter 4: Threads. Overview Multithreading Models Thread Libraries Threading Issues Operating System Examples Windows XP Threads Linux Threads

COSC 6385 Computer Architecture - Thread Level Parallelism (III)

AN 831: Intel FPGA SDK for OpenCL

RTEMS SMP Features Joel Sherrill, Ph.D.

Migrating Mappings and Mapplets from a PowerCenter Repository to a Model Repository

Chapter 4: Threads. Operating System Concepts 9 th Edition

Chapter 4: Threads. Operating System Concepts 8 th Edition,

THREADS. Jo, Heeseung

Real Time and Embedded Systems. by Dr. Lesley Shannon Course Website:

Introduction to Threads

Systems software design. Processes, threads and operating system resources

IX: A Protected Dataplane Operating System for High Throughput and Low Latency

Threads. Threads (continued)

Increasing Performance for PowerCenter Sessions that Use Partitions

Assignment 2 Group 5 Simon Gerber Systems Group Dept. Computer Science ETH Zurich - Switzerland

Questions answered in this lecture: CS 537 Lecture 19 Threads and Cooperation. What s in a process? Organizing a Process

Operating Systems. VI. Threads. Eurecom. Processes and Threads Multithreading Models

CSE398: Network Systems Design

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

518 Lecture Notes Week 5

Operating Systems. Review ENCE 360

COSC 6385 Computer Architecture. - Thread Level Parallelism (III)

Running PowerCenter Advanced Edition in Split Domain Mode

Universal Contact Server Manager. Release Notes 8.5.x

CPSC 341 OS & Networks. Introduction. Dr. Yingwu Zhu

Application Acceleration Beyond Flash Storage

Concurrent Server Design Multiple- vs. Single-Thread

Transcription:

Setting Thread Affinity in Ultra Messaging Applications 2014 Informatica Corporation. No part of this document may be reproduced or transmitted in any form, by any means (electronic, photocopying, recording or otherwise) without prior consent of Informatica Corporation. All other company and product names may be trade names or trademarks of their respective owners and/or copyrighted materials of such owners.

Abstract You can force program processes or threads to run on specific processors or cores. This is typically referred to with a variety of names: thread affinity (the term used in, and the focus of, this article), process affinity, processor affinity, CPU affinity, or CPU pinning. Basically, we are binding a process or thread to a CPU or core. Supported Versions Ultra Messaging 6.7 and earlier Table of Contents Thread Management and Message Latency.... 2 Operational Mode.... 2 Context Thread Embedded Mode.... 3 Context Thread Sequential Mode.... 3 LBT-IPC Transport Operational Modes.... 3 Thread Affinity.... 3 C vs. Java/.NET.... 3 Platforms.... 3 Getting the Thread ID.... 3 Setting Affinity.... 4 Java Notes.... 4.NET/C# Notes.... 4 Variations and Conclusion.... 5 Thread Management and Message Latency For machines that run messaging applications, binding a messaging thread to a core reduces variations in that application's performance latencies to a smaller range. This increases the application's performance predictability and manageability, or, in a sense, reduces jitter. However, note that using thread affinity does not guarantee performance improvements, and in some cases may even degrade the application's performance. You can set thread affinity by setting application configuration options or issuing command-line commands, but for Ultra Messaging and this article, we explore a programmatic approach using system or library calls. The thread affinity call assigns an affinity mask value to a thread ID. An affinity mask is a thread or process bit mask that instructs an operating system scheduler which CPU or core to run on. Using a system call from C to set thread affinity is fairly straightforward; however, the challenges in Ultra Messaging lie in a) determining the thread ID, and b) using Java or.net languages to access this functionality. Operational Mode Ultra Messaging offers a choice of how event-processing threads are created with the context operational_mode configuration option, with either embedded mode or sequential mode. You can set thread affinity in either mode: 2

Context Thread Embedded Mode When you create a context, Ultra Messaging creates an independent context thread, which handles timer and socket events, and which does protocol-level processing, like retransmission of dropped packets. Ultra Messaging also creates, per context, one IPC, SMX, or RDMA thread for a receiver of the corresponding transport type. To set thread affinity in embedded mode, you must wait for Ultra Messaging to create the thread and deliver an event. Context Thread Sequential Mode Upon context creation, Ultra Messaging does not create a context thread. Instead, the application must donate a thread by calling lbm_context_process_events() when needed. Sequential mode lets the application control when and for how long the context thread runs. With sequential mode, you can call lbm_context_process_events() on any thread to do things such as Set a thread's timeout, so that the application regains control by the end of a desired period. Set thread affinity on a thread before calling any Ultra Messaging functions. LBT-IPC Transport Operational Modes You can also set operational mode for message-processing threads using the LBT-IPC transport. When you set option transport_lbtipc_receiver_operational_mode to sequential, the application calls lbm_context_process_lbtipc_messages() to process received LBT-IPC messages. However, this works only with the Ultra Messaging C API, because equivalent message processing calls do not exist in the Ultra Messaging Java or.net APIs. Thread Affinity To set affinity, first determine which is the context thread, and also if applicable, which thread is handling IPC, SMX, or RDMA reception. Also determine how to get a callback on that thread. With the thread ID you can then call the function to pin the thread to a core. For most UNIX platforms, the POSIX Threads API pthread_setaffinity_np() function sets the CPU affinity mask of the thread to the CPU set pointed to by cpuset. If the call is successful, and the thread is not currently running on one of the CPUs in cpuset, then it is migrated to one of those CPUs. The pthread_getaffinity_np() function returns the CPU affinity mask of the thread in the buffer pointed to by cpuset. C vs. Java/.NET C code can make system calls and therefore, has direct access to the thread. Java does not offer this access, however, you can use the JNI (Java Native Interface) or JNA (Java Native Access) libraries to call native (platformspecific) code. For.NET programming, the Platform Invocation Services (P/Invoke) feature enables.net code to call native code. Platforms Since we perform thread management at the platform or OS level, there are variations to system calls or their arguments. Thus, this article provides general programmatic approaches to setting thread affinity. Depending on your platform and thread type, you must use the system call that is appropriate for your platform. Getting the Thread ID You can call a system call from within a thread that returns a thread ID, for example pthread_self(). 3

Setting Affinity When setting affinity, first determine the right time to effectively pin the thread. For example, a good place to set thread affinity is on receipt of a BOS message, as in the following example: int rcv_handle_msg(lbm_rcv_t *rcv, lbm_msg_t *msg, void *clientd) { if (msg->type == LBM_MSG_BOS) { thread_set_affinity( ); where thread_set_affinity( ) is a generic for the actual system call you use based on platform. The following table shows platform-based affinity system calls: Platform To Get Thread ID To Set Affinity AIX pthread_self() bindprocessor() Darwin/OS-X pthread_self() thread_policy_set() HP-UX pthread_self() pthread_processor_bind_np( ) Linux pthread_self(), pthread_getthreadid_np() pthread_setaffinity_np() Solaris/SunOS thr_self() processor_bind() Win32 GetCurrentThreadId() SetThreadAffinityMask() Note that the preceding UNIX call examples use POSIX Threads (pthreads). Java Notes Peter Lawrey's Java-Thread-Affinity library uses JNI and JNA and lets you assign critical threads to isolated CPUs/ cores. See the following URL: https://github.com/peter-lawrey/java-thread-affinity For example, you can call the API setaffinity() to bind the current thread to the desired CPU, as in the following: // In receiver callback if (msg.type() == LBM.MSG_BOS) { int cpuid = 3; AffinitySupport.setAffinity(1L << cpuid); Likewise, AffinitySupport.getAffinity() returns the current thread's affinity..net/c# Notes.NET programming deals with managed threads, which are essentially OS threads with the Thread object attached. Use the P/Invoke feature to call the desired OS thread API. For example: [DllImport("kernel32.dll")] public static extern int GetCurrentThreadId(); /// <summary> /// Set the current thread affinity to cpumask /// </summary> public static void setthreadaffinity(int cpumask) { 4

Thread.BeginThreadAffinity(); int currthreadid = GetCurrentThreadId(); foreach (ProcessThread currthread in process.threads) { if (currthread.id == currthreadid) { currthread.processoraffinity = new IntPtr(cpuMask); currthread.prioritylevel = ThreadPriorityLevel.Highest; break; // In receiver callback if (msg.type() == LBM.MSG_BOS) { int cpuid = 3; setthreadaffinity(1 << cpuid); Variations and Conclusion This article addresses an approach for setting thread affinity in Ultra Messaging applications, but can also serve as a model for other thread management operations, such as setting thread priority. Also note that you can approach thread management by setting attributes to use when creating threads. Author Nate Stelton Technical Writer Acknowledgements Thanks to Eric Bowden and Brian Horst. 5