Skip to content

Latest commit

 

History

History
260 lines (236 loc) · 6.76 KB

230303.md

File metadata and controls

260 lines (236 loc) · 6.76 KB

230303 성능테스트

[Community] GET Server

(카테고리 10개)*(채널 3개) 스크린샷 2023-03-03 오후 2 00 42

Numbers of Threads (users): 1000 Ramp-up period (seconds): 10 Loop Count: 100

Label # Samples Average Min Max Std. Dev. Error % Throughput Received KB/sec Sent KB/sec Avg. Bytes
GET server?id 100000 1413 16 2544 264.61 0.0 657.6524 1496.416 197.80 2330.0
GET server?id 100000 1434 17 2799 277.9865393729115 0.0 648.3696744535864 1475.2942787859927 195.0174411442428 2330.0
Label # Samples Average Min Max Std. Dev. Error % Throughput Received KB/sec Sent KB/sec Avg. Bytes
GET server?id 100000 357 6 1947 180.33 0.0 478.215 1087.99 143.84 2329.7
GET server?id 100000 329 6 791 111.86071799336183 0.0 2321.208885587614 5280.999563322578 698.1761101181495 2329.71

reaction 개선 전 코드

public class ReactionService {

    private final MessageRepository messageRepository;
    private final UserClient userClient;

    @Transactional
    public ReactionMessageResponse reactMessage(ReactionRequest reactionRequest, Long userId) {

        UserResponse user = userClient.getUser(userId);

        Message message = messageRepository.findById(reactionRequest.getMessageId())
                .orElseThrow(() -> new DistoveException(MESSAGE_NOT_FOUND_ERROR));


        List<Reaction> reactions = message.getReactions();
        if (reactions == null) {
            reactions = new ArrayList<Reaction>();
        }

        Optional<Reaction> reaction = reactions.stream().filter(r -> r.getEmoji().equals(reactionRequest.getEmoji()))
                .findFirst();

        List<ReactionResponse> reactionResponses = new ArrayList<>();

        if (reaction.isEmpty()) {
            Reaction createdNewReaction = newReaction(reactionRequest.getEmoji(), new ArrayList<Long>() {{
                add(userId);
            }});
            reactions.add(createdNewReaction);
            reactionResponses.add(newReactionResponse(createdNewReaction.getEmoji(), new ArrayList<UserResponse>() {{
                add(user);
            }}));
        } else {
            //이미 사용됐던 emoji라면
            List<Long> userIds = reaction.get().getUserIds();
            //내가 이미 눌렀던 emoji면 삭제하고

            if (!userIds.removeIf(id -> id.equals(userId))) {
                // if not removed
                userIds.add(userId);

            }

            //다 했는데(취소) 만약 비었다면
            if (userIds.isEmpty()) {

                reactions.removeIf(r -> reaction.get().getEmoji().equals(r.getEmoji()));
            }
        }
        for (Reaction r : reactions) {
            String userIdsString = r.getUserIds().toString().replace("[","").replace("]","");
            List<UserResponse> userResponses = userClient.getUsers(userIdsString);
            reactionResponses.add(newReactionResponse(r.getEmoji(),userClient.getUsers(userIdsString)));
        }
        message.updateReaction(reactions);
        messageRepository.save(message);

        return newReactionMessageResponse(reactionRequest.getMessageId(),reactionResponses);
    }

}

스크린샷 2023-03-03 오후 9 01 35

스크린샷 2023-03-03 오후 9 01 46

{
  "messageId": "64094c1b45c6cc6b0638a082",
  "status": "REACTED",
  "reactions": [
    {
      "emoji": "1f600",
      "users": [
        {
          "id": 72,
          "nickname": "박현성"
        }
      ]
    },
    {
      "emoji": "1f604",
      "users": [
        {
          "id": 72,
          "nickname": "박현성"
        }
      ]
    },
    {
      "emoji": "1f349",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f606",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f9ba",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f30f",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f6ba",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f603",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f435",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f952",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f49f",
      "users": [
        {
          "id": 72,
          "nickname": "박현성"
        }
      ]
    },
    {
      "emoji": "1f976",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f64b-200d-2640-fe0f",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f44c",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f440",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f984",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f436",
      "users": [
        {
          "id": 97,
          "nickname": "이수진"
        }
      ]
    },
    {
      "emoji": "1f4ab",
      "users": [
        {
          "id": 72,
          "nickname": "박현성"
        }
      ]
    }
  ]
}