Skip to content

Commit

Permalink
Add allocation counter tests for isolated EL operations
Browse files Browse the repository at this point in the history
Motivation:

As with the ELF operations before them, the isolated EL operations currently
incur overhead above-and-beyond the overhead of their non-isolated counterparts.
That's not what we want to see. However, before we "fix" them, we need to add
regression testing to confirm our fix actually worked.

Modifications:

- Add isolated variations of all current EL scheduling tests.
- Where isolated methods didn't have alloc counter tests, add new ones
    for the non-isolated versions too.

Result:

More tests.
  • Loading branch information
Lukasa committed Jan 17, 2025
1 parent f5773c1 commit d681296
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2017-2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Dispatch
import NIOPosix

func run(identifier: String) {
measure(identifier: identifier) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let loop = group.next()
let dg = DispatchGroup()

try! loop.submit {
for _ in 0..<10_000 {
dg.enter()
loop.assumeIsolated().execute { dg.leave() }
}
}.wait()
dg.wait()
try! group.syncShutdownGracefully()
return 10_000
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019-2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Dispatch
import NIOCore
import NIOPosix

func run(identifier: String) {
measure(identifier: identifier) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let loop = group.next()
let counter = try! loop.submit { () -> Int in
var counter: Int = 0

let deadline = NIODeadline.now() + .hours(1)

for _ in 0..<10000 {
loop.flatScheduleTask(deadline: deadline) {
counter &+= 1
return loop.makeSucceededFuture(counter)
}
}

return counter
}.wait()

try! group.syncShutdownGracefully()
return counter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019-2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Dispatch
import NIOCore
import NIOPosix

func run(identifier: String) {
measure(identifier: identifier) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let loop = group.next()
let counter = try! loop.submit { () -> Int in
var counter: Int = 0

let deadline = NIODeadline.now() + .hours(1)

for _ in 0..<10000 {
loop.assumeIsolated().flatScheduleTask(deadline: deadline) {
counter &+= 1
return loop.makeSucceededFuture(counter)
}
}

return counter
}.wait()

try! group.syncShutdownGracefully()
return counter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019-2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Dispatch
import NIOPosix

func run(identifier: String) {
measure(identifier: identifier) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let loop = group.next()
let counter = try! loop.submit { () -> Int in
var counter: Int = 0

for _ in 0..<10000 {
loop.assumeIsolated().scheduleTask(in: .hours(1)) {
counter &+= 1
}
}

return counter
}.wait()

try! group.syncShutdownGracefully()
return counter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019-2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Dispatch
import NIOCore
import NIOPosix

func run(identifier: String) {
measure(identifier: identifier) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let loop = group.next()
let counter = try! loop.submit { () -> Int in
var counter: Int = 0

let deadline = NIODeadline.now() + .hours(1)

for _ in 0..<10000 {
loop.scheduleTask(deadline: deadline) {
counter &+= 1
}
}

return counter
}.wait()

try! group.syncShutdownGracefully()
return counter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019-2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Dispatch
import NIOCore
import NIOPosix

func run(identifier: String) {
measure(identifier: identifier) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let loop = group.next()
let counter = try! loop.submit { () -> Int in
var counter: Int = 0

let deadline = NIODeadline.now() + .hours(1)

for _ in 0..<10000 {
loop.assumeIsolated().scheduleTask(deadline: deadline) {
counter &+= 1
return counter
}
}

return counter
}.wait()

try! group.syncShutdownGracefully()
return counter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019-2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Dispatch
import NIOPosix

func run(identifier: String) {
measure(identifier: identifier) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let loop = group.next()
let counter = try! loop.submit { () -> Int in
var counter: Int = 0

for _ in 0..<10000 {
_ = loop.submit {
counter &+= 1
return counter
}
}

return counter
}.wait()

try! group.syncShutdownGracefully()
return counter
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftNIO open source project
//
// Copyright (c) 2019-2025 Apple Inc. and the SwiftNIO project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

import Dispatch
import NIOPosix

func run(identifier: String) {
measure(identifier: identifier) {
let group = MultiThreadedEventLoopGroup(numberOfThreads: 1)
let loop = group.next()
let counter = try! loop.submit { () -> Int in
var counter: Int = 0

for _ in 0..<10000 {
_ = loop.assumeIsolated().submit {
counter &+= 1
return counter
}
}

return counter
}.wait()

try! group.syncShutdownGracefully()
return counter
}
}

0 comments on commit d681296

Please sign in to comment.