Skip to content

Commit ea5d580

Browse files
committed
perf: remove unnecesarry mutex in the session store
1 parent 5bf54d6 commit ea5d580

File tree

6 files changed

+124
-149
lines changed

6 files changed

+124
-149
lines changed

.release-config.json

Lines changed: 104 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,110 @@
11
{
2-
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3-
"release-type": "rust",
4-
"release-as": "",
5-
"include-component-in-tag": true,
6-
"changelog-sections": [
7-
{
8-
"type": "feature",
9-
"section": "🚀 Features"
10-
},
11-
{
12-
"type": "feat",
13-
"section": "🚀 Features"
14-
},
15-
{
16-
"type": "fix",
17-
"section": "🐛 Bug Fixes"
18-
},
19-
{
20-
"type": "perf",
21-
"section": "⚡ Performance Improvements"
22-
},
23-
{
24-
"type": "revert",
25-
"section": "◀️ Reverts"
26-
},
27-
{
28-
"type": "docs",
29-
"section": "📚 Documentation",
30-
"hidden": false
31-
},
32-
{
33-
"type": "style",
34-
"section": "🎨 Styles",
35-
"hidden": true
36-
},
37-
{
38-
"type": "chore",
39-
"section": "⚙️ Miscellaneous Chores",
40-
"hidden": true
41-
},
42-
{
43-
"type": "refactor",
44-
"section": "🚜 Code Refactoring",
45-
"hidden": true
46-
},
47-
{
48-
"type": "test",
49-
"section": "🧪 Tests",
50-
"hidden": true
51-
},
2+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3+
"release-type": "rust",
4+
"release-as": "",
5+
"include-component-in-tag": true,
6+
"changelog-sections": [
7+
{
8+
"type": "feature",
9+
"section": "🚀 Features"
10+
},
11+
{
12+
"type": "feat",
13+
"section": "🚀 Features"
14+
},
15+
{
16+
"type": "fix",
17+
"section": "🐛 Bug Fixes"
18+
},
19+
{
20+
"type": "perf",
21+
"section": "⚡ Performance Improvements",
22+
"hidden": false
23+
},
24+
{
25+
"type": "revert",
26+
"section": "◀️ Reverts"
27+
},
28+
{
29+
"type": "docs",
30+
"section": "📚 Documentation",
31+
"hidden": false
32+
},
33+
{
34+
"type": "style",
35+
"section": "🎨 Styles",
36+
"hidden": true
37+
},
38+
{
39+
"type": "chore",
40+
"section": "⚙️ Miscellaneous Chores",
41+
"hidden": true
42+
},
43+
{
44+
"type": "refactor",
45+
"section": "🚜 Code Refactoring",
46+
"hidden": false
47+
},
48+
{
49+
"type": "test",
50+
"section": "🧪 Tests",
51+
"hidden": true
52+
},
53+
{
54+
"type": "build",
55+
"section": "🛠️ Build System",
56+
"hidden": true
57+
},
58+
{
59+
"type": "ci",
60+
"section": "🥏 Continuous Integration",
61+
"hidden": true
62+
}
63+
],
64+
"plugins": ["cargo-workspace", "sentence-case"],
65+
"pull-request-header": ":robot: Auto-generated release PR",
66+
"packages": {
67+
"crates/rust-mcp-macros": {
68+
"release-type": "rust",
69+
"draft": false,
70+
"prerelease": false,
71+
"bump-minor-pre-major": true,
72+
"bump-patch-for-minor-pre-major": true,
73+
"changelogPath": "CHANGELOG.md",
74+
"extra-files": [
5275
{
53-
"type": "build",
54-
"section": "🛠️ Build System",
55-
"hidden": true
56-
},
76+
"type": "generic",
77+
"path": "CHANGELOG.md"
78+
}
79+
]
80+
},
81+
"crates/rust-mcp-transport": {
82+
"release-type": "rust",
83+
"draft": false,
84+
"prerelease": false,
85+
"bump-minor-pre-major": true,
86+
"bump-patch-for-minor-pre-major": true,
87+
"changelogPath": "CHANGELOG.md",
88+
"extra-files": [
5789
{
58-
"type": "ci",
59-
"section": "🥏 Continuous Integration",
60-
"hidden": true
90+
"type": "generic",
91+
"path": "CHANGELOG.md"
6192
}
62-
],
63-
"plugins": [
64-
"cargo-workspace",
65-
"sentence-case"
66-
],
67-
"pull-request-header": ":robot: Auto-generated release PR",
68-
"packages": {
69-
"crates/rust-mcp-macros": {
70-
"release-type": "rust",
71-
"draft": false,
72-
"prerelease": false,
73-
"bump-minor-pre-major": true,
74-
"bump-patch-for-minor-pre-major": true,
75-
"changelogPath": "CHANGELOG.md",
76-
"extra-files": [
77-
{
78-
"type": "generic",
79-
"path": "CHANGELOG.md"
80-
}
81-
]
82-
},
83-
"crates/rust-mcp-transport": {
84-
"release-type": "rust",
85-
"draft": false,
86-
"prerelease": false,
87-
"bump-minor-pre-major": true,
88-
"bump-patch-for-minor-pre-major": true,
89-
"changelogPath": "CHANGELOG.md",
90-
"extra-files": [
91-
{
92-
"type": "generic",
93-
"path": "CHANGELOG.md"
94-
}
95-
]
96-
},
97-
"crates/rust-mcp-sdk": {
98-
"release-type": "rust",
99-
"draft": false,
100-
"prerelease": false,
101-
"bump-minor-pre-major": true,
102-
"bump-patch-for-minor-pre-major": true,
103-
"changelogPath": "CHANGELOG.md",
104-
"extra-files": [
105-
{
106-
"type": "generic",
107-
"path": "CHANGELOG.md"
108-
}
109-
]
93+
]
94+
},
95+
"crates/rust-mcp-sdk": {
96+
"release-type": "rust",
97+
"draft": false,
98+
"prerelease": false,
99+
"bump-minor-pre-major": true,
100+
"bump-patch-for-minor-pre-major": true,
101+
"changelogPath": "CHANGELOG.md",
102+
"extra-files": [
103+
{
104+
"type": "generic",
105+
"path": "CHANGELOG.md"
110106
}
107+
]
111108
}
112-
}
109+
}
110+
}

crates/rust-mcp-sdk/src/hyper_servers/hyper_runtime.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::{
1515

1616
use axum_server::Handle;
1717
use rust_mcp_transport::SessionId;
18-
use tokio::{sync::Mutex, task::JoinHandle};
18+
use tokio::task::JoinHandle;
1919

2020
use crate::{
2121
error::SdkResult,
@@ -79,7 +79,7 @@ impl HyperRuntime {
7979
pub async fn runtime_by_session(
8080
&self,
8181
session_id: &SessionId,
82-
) -> TransportServerResult<Arc<Mutex<Arc<ServerRuntime>>>> {
82+
) -> TransportServerResult<Arc<ServerRuntime>> {
8383
self.state.session_store.get(session_id).await.ok_or(
8484
TransportServerError::SessionIdInvalid(session_id.to_string()),
8585
)
@@ -92,7 +92,6 @@ impl HyperRuntime {
9292
timeout: Option<Duration>,
9393
) -> SdkResult<ResultFromClient> {
9494
let runtime = self.runtime_by_session(session_id).await?;
95-
let runtime = runtime.lock().await.to_owned();
9695
runtime.request(request, timeout).await
9796
}
9897

@@ -102,7 +101,6 @@ impl HyperRuntime {
102101
notification: NotificationFromServer,
103102
) -> SdkResult<()> {
104103
let runtime = self.runtime_by_session(session_id).await?;
105-
let runtime = runtime.lock().await.to_owned();
106104
runtime.send_notification(notification).await
107105
}
108106

@@ -117,7 +115,6 @@ impl HyperRuntime {
117115
params: Option<ListRootsRequestParams>,
118116
) -> SdkResult<ListRootsResult> {
119117
let runtime = self.runtime_by_session(session_id).await?;
120-
let runtime = runtime.lock().await.to_owned();
121118
runtime.list_roots(params).await
122119
}
123120

@@ -127,7 +124,6 @@ impl HyperRuntime {
127124
params: LoggingMessageNotificationParams,
128125
) -> SdkResult<()> {
129126
let runtime = self.runtime_by_session(session_id).await?;
130-
let runtime = runtime.lock().await.to_owned();
131127
runtime.send_logging_message(params).await
132128
}
133129

@@ -140,7 +136,6 @@ impl HyperRuntime {
140136
params: Option<PromptListChangedNotificationParams>,
141137
) -> SdkResult<()> {
142138
let runtime = self.runtime_by_session(session_id).await?;
143-
let runtime = runtime.lock().await.to_owned();
144139
runtime.send_prompt_list_changed(params).await
145140
}
146141

@@ -153,7 +148,6 @@ impl HyperRuntime {
153148
params: Option<ResourceListChangedNotificationParams>,
154149
) -> SdkResult<()> {
155150
let runtime = self.runtime_by_session(session_id).await?;
156-
let runtime = runtime.lock().await.to_owned();
157151
runtime.send_resource_list_changed(params).await
158152
}
159153

@@ -166,7 +160,6 @@ impl HyperRuntime {
166160
params: ResourceUpdatedNotificationParams,
167161
) -> SdkResult<()> {
168162
let runtime = self.runtime_by_session(session_id).await?;
169-
let runtime = runtime.lock().await.to_owned();
170163
runtime.send_resource_updated(params).await
171164
}
172165

@@ -179,7 +172,6 @@ impl HyperRuntime {
179172
params: Option<ToolListChangedNotificationParams>,
180173
) -> SdkResult<()> {
181174
let runtime = self.runtime_by_session(session_id).await?;
182-
let runtime = runtime.lock().await.to_owned();
183175
runtime.send_tool_list_changed(params).await
184176
}
185177

@@ -199,7 +191,6 @@ impl HyperRuntime {
199191
timeout: Option<Duration>,
200192
) -> SdkResult<crate::schema::Result> {
201193
let runtime = self.runtime_by_session(session_id).await?;
202-
let runtime = runtime.lock().await.to_owned();
203194
runtime.ping(timeout).await
204195
}
205196

@@ -214,7 +205,6 @@ impl HyperRuntime {
214205
params: CreateMessageRequestParams,
215206
) -> SdkResult<CreateMessageResult> {
216207
let runtime = self.runtime_by_session(session_id).await?;
217-
let runtime = runtime.lock().await.to_owned();
218208
runtime.create_message(params).await
219209
}
220210

@@ -223,7 +213,6 @@ impl HyperRuntime {
223213
session_id: &SessionId,
224214
) -> SdkResult<Option<InitializeRequestParams>> {
225215
let runtime = self.runtime_by_session(session_id).await?;
226-
let runtime = runtime.lock().await.to_owned();
227216
Ok(runtime.client_info())
228217
}
229218
}

crates/rust-mcp-sdk/src/mcp_http/mcp_http_handler.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl McpHttpHandler {
115115
TransportServerError::SessionIdInvalid(session_id.to_string()),
116116
)?;
117117

118-
let transmit = transmit.lock().await;
119118
let message = *request.body();
120119
transmit
121120
.consume_payload_string(DEFAULT_STREAM_ID, message)

crates/rust-mcp-sdk/src/mcp_http/mcp_http_utils.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ pub async fn create_standalone_stream(
240240
let runtime = state.session_store.get(&session_id).await.ok_or(
241241
TransportServerError::SessionIdInvalid(session_id.to_string()),
242242
)?;
243-
let runtime = runtime.lock().await.to_owned();
244243

245244
if runtime.stream_id_exists(DEFAULT_STREAM_ID).await {
246245
let error =
@@ -410,8 +409,6 @@ pub async fn process_incoming_message_return(
410409
) -> TransportServerResult<http::Response<GenericBody>> {
411410
match state.session_store.get(&session_id).await {
412411
Some(runtime) => {
413-
let runtime = runtime.lock().await.to_owned();
414-
415412
single_shot_stream(
416413
runtime.clone(),
417414
session_id,
@@ -437,7 +434,6 @@ pub async fn process_incoming_message(
437434
) -> TransportServerResult<http::Response<GenericBody>> {
438435
match state.session_store.get(&session_id).await {
439436
Some(runtime) => {
440-
let runtime = runtime.lock().await.to_owned();
441437
// when receiving a result in a streamable_http server, that means it was sent by the standalone sse transport
442438
// it should be processed by the same transport , therefore no need to call create_sse_stream
443439
let Ok(is_result) = is_result(payload) else {
@@ -494,7 +490,6 @@ pub async fn delete_session(
494490
) -> TransportServerResult<http::Response<GenericBody>> {
495491
match state.session_store.get(&session_id).await {
496492
Some(runtime) => {
497-
let runtime = runtime.lock().await.to_owned();
498493
runtime.shutdown().await;
499494
state.session_store.delete(&session_id).await;
500495
tracing::info!("client disconnected : {}", &session_id);

0 commit comments

Comments
 (0)