Skip to content

Commit fbb9199

Browse files
authored
Merge pull request #120 from rsocket/refactoring
refactoring
2 parents 6943cde + 027fb1d commit fbb9199

23 files changed

+485
-257
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ pip install rsocket
1515

1616
You may also install using some **extras**:
1717

18-
| Extra | Functionality |
19-
|------------|-------------------------------------|
20-
| rx | ReactiveX (v3) integration |
21-
| reactivex | ReactiveX (v4) integration |
22-
| aiohttp | Websocket transport (server/client) |
23-
| quart | Websocket transport (server only) |
24-
| quic | QUIC transport |
25-
| cli | Command line |
18+
| Extra | Functionality |
19+
|-----------|-------------------------------------|
20+
| rx | ReactiveX (v3) integration |
21+
| reactivex | ReactiveX (v4) integration |
22+
| aiohttp | Websocket transport (server/client) |
23+
| quart | Websocket transport (server only) |
24+
| quic | QUIC transport |
25+
| cli | Command line |
26+
| optimized | Frame parse/serialize optimizations |
2627

2728
```shell
2829
pip install rsocket[reactivex]

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525

2626
# The full version, including alpha/beta/rc tags
27-
release = '0.4.8'
27+
release = '0.4.9'
2828

2929
# -- General configuration ---------------------------------------------------
3030

performance/performance_client.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import logging
3+
import sys
34
from asyncio import Event
45
from typing import AsyncGenerator, Tuple
56

@@ -14,7 +15,7 @@
1415
from rsocket.streams.stream_from_async_generator import StreamFromAsyncGenerator
1516
from rsocket.transports.tcp import TransportTCP
1617
from tests.rsocket.helpers import to_json_bytes, create_large_random_data
17-
18+
from tests.tools.helpers import measure_time
1819

1920
data_size = 1920 # * 1080 * 3
2021
large_data = create_large_random_data(data_size)
@@ -104,7 +105,7 @@ async def request_fragmented_stream(self):
104105
async def __aenter__(self):
105106
logging.info('Connecting to server at localhost:%s', self._server_port)
106107

107-
connection = await asyncio.open_connection('localhost', self._server_port)
108+
connection = await asyncio.open_connection('localhost', self._server_port, limit=data_size + 3000)
108109

109110
self._client = AwaitableRSocket(RSocketClient(
110111
single_transport_provider(TransportTCP(*connection, read_buffer_size=data_size + 3000)),
@@ -116,3 +117,16 @@ async def __aenter__(self):
116117

117118
async def __aexit__(self, exc_type, exc_val, exc_tb):
118119
await self._client.__aexit__(exc_type, exc_val, exc_tb)
120+
121+
122+
async def run_client():
123+
async with PerformanceClient(6565) as client:
124+
for i in range(10000):
125+
result = await measure_time(client.large_request())
126+
# print(result.delta)
127+
128+
129+
if __name__ == '__main__':
130+
port = sys.argv[1] if len(sys.argv) > 1 else 6565
131+
logging.basicConfig(level=logging.ERROR)
132+
asyncio.run(run_client())

performance/performance_server.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from performance.sample_responses import response_stream_2, response_stream_1, LoggingSubscriber
1818
from tests.rsocket.helpers import create_large_random_data
1919

20-
data_size = 1920 # * 1080 * 3
20+
data_size = 1920 * 1080 * 3
2121
large_data = create_large_random_data(data_size)
2222

2323
router = RequestRouter()
@@ -124,7 +124,7 @@ def handle_client(reader, writer):
124124
async def run_server(server_port, on_ready=None):
125125
logging.info('Starting server at localhost:%s', server_port)
126126

127-
server = await asyncio.start_server(client_handler_factory(on_ready), 'localhost', server_port)
127+
server = await asyncio.start_server(client_handler_factory(on_ready), 'localhost', server_port, limit=data_size)
128128

129129
async with server:
130130
await server.serve_forever()

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ pytest-xdist==3.2.0
1616
pytest==7.2.1
1717
quart==0.18.3
1818
reactivex==4.0.4
19-
starlette==0.25.0
19+
starlette==0.25.0
20+
cbitstruct==1.0.9

rsocket/extensions/authentication_content.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ def __init__(self, authentication: Optional[Authentication] = None):
1515
self.authentication = authentication
1616

1717
def serialize(self) -> bytes:
18-
serialized = b''
19-
20-
serialized += serialize_well_known_encoding(self.authentication.type, WellKnownAuthenticationTypes.get_by_name)
18+
serialized = serialize_well_known_encoding(self.authentication.type, WellKnownAuthenticationTypes.get_by_name)
2119

2220
serialized += self.authentication.serialize()
2321

@@ -29,10 +27,11 @@ def parse(self, buffer: bytes):
2927
self.authentication.parse(buffer[offset:])
3028

3129

32-
def authentication_item_factory(metadata_encoding: bytes) -> Type[Authentication]:
33-
metadata_item_factory_by_type = {
34-
WellKnownAuthenticationTypes.SIMPLE.value.name: AuthenticationSimple,
35-
WellKnownAuthenticationTypes.BEARER.value.name: AuthenticationBearer,
36-
}
30+
metadata_item_factory_by_type = {
31+
WellKnownAuthenticationTypes.SIMPLE.value.name: AuthenticationSimple,
32+
WellKnownAuthenticationTypes.BEARER.value.name: AuthenticationBearer,
33+
}
3734

35+
36+
def authentication_item_factory(metadata_encoding: bytes) -> Type[Authentication]:
3837
return metadata_item_factory_by_type[metadata_encoding]

rsocket/extensions/authentication_types.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from typing import Optional
33

44
from rsocket.exceptions import RSocketUnknownAuthType
5-
from rsocket.helpers import WellKnownType, map_types_by_id, map_types_by_name
5+
from rsocket.helpers import WellKnownType, map_type_names_by_id, \
6+
map_type_ids_by_name
67

78

89
class WellKnownAuthenticationType(WellKnownType):
@@ -26,5 +27,5 @@ def get_by_name(cls, metadata_name: str) -> Optional[WellKnownAuthenticationType
2627
return type_by_name.get(metadata_name)
2728

2829

29-
type_by_id = map_types_by_id(WellKnownAuthenticationTypes)
30-
type_by_name = map_types_by_name(WellKnownAuthenticationTypes)
30+
type_by_id = map_type_names_by_id(WellKnownAuthenticationTypes)
31+
type_by_name = map_type_ids_by_name(WellKnownAuthenticationTypes)

rsocket/extensions/composite_metadata.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ def default_or_value(value, default=None):
1818
return value
1919

2020

21-
def metadata_item_factory(metadata_encoding: bytes) -> Type[CompositeMetadataItem]:
22-
metadata_item_factory_by_type = {
23-
WellKnownMimeTypes.MESSAGE_RSOCKET_ROUTING.value.name: RoutingMetadata,
24-
WellKnownMimeTypes.MESSAGE_RSOCKET_MIMETYPE.value.name: StreamDataMimetype,
25-
WellKnownMimeTypes.MESSAGE_RSOCKET_ACCEPT_MIMETYPES.value.name: StreamDataMimetypes,
26-
WellKnownMimeTypes.MESSAGE_RSOCKET_AUTHENTICATION.value.name: AuthenticationContent
27-
}
21+
metadata_item_factory_by_type = {
22+
WellKnownMimeTypes.MESSAGE_RSOCKET_ROUTING.value.name: RoutingMetadata,
23+
WellKnownMimeTypes.MESSAGE_RSOCKET_MIMETYPE.value.name: StreamDataMimetype,
24+
WellKnownMimeTypes.MESSAGE_RSOCKET_ACCEPT_MIMETYPES.value.name: StreamDataMimetypes,
25+
WellKnownMimeTypes.MESSAGE_RSOCKET_AUTHENTICATION.value.name: AuthenticationContent
26+
}
27+
2828

29+
def metadata_item_factory(metadata_encoding: bytes) -> Type[CompositeMetadataItem]:
2930
return metadata_item_factory_by_type.get(metadata_encoding, CompositeMetadataItem)
3031

3132

rsocket/extensions/mimetypes.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from rsocket.exceptions import RSocketUnknownMimetype
55
from rsocket.extensions.mimetype import WellKnownMimeType
66
from rsocket.frame_helpers import ensure_bytes
7-
from rsocket.helpers import map_types_by_id, map_types_by_name
7+
from rsocket.helpers import map_type_names_by_id, map_type_ids_by_name
88

99

1010
@unique
@@ -80,8 +80,8 @@ def get_by_name(cls, metadata_name: str) -> Optional[WellKnownMimeType]:
8080
return mimetype_by_name.get(metadata_name)
8181

8282

83-
mimetype_by_id = map_types_by_id(WellKnownMimeTypes)
84-
mimetype_by_name = map_types_by_name(WellKnownMimeTypes)
83+
mimetype_by_id = map_type_names_by_id(WellKnownMimeTypes)
84+
mimetype_by_name = map_type_ids_by_name(WellKnownMimeTypes)
8585

8686

8787
def ensure_encoding_name(encoding: Union[WellKnownMimeTypes, str, bytes]) -> bytes:

0 commit comments

Comments
 (0)