Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Getting late response from Spray-Client #1139

Open
dharmeshpkk opened this issue Apr 3, 2020 · 0 comments
Open

Getting late response from Spray-Client #1139

dharmeshpkk opened this issue Apr 3, 2020 · 0 comments

Comments

@dharmeshpkk
Copy link

dharmeshpkk commented Apr 3, 2020

I'm using a spray-client to hit another server request. From front-end it is reactjs. I am able to abort a request from reactJS. And it shows in the network tab of browser console that the request is canceled. On every key-stroke, I'm calling an API if I get the next key-stroke and don't get a response from the previous key-stroke then I abort(using AbortController()) I'm canceling the previous request and so on.

So in this, I'm hitting spray API which internally hits another server using spray-client. So I'm getting a response after exactly 22 seconds on the last key-stroke.
This is the configuration I'm using for spray:

spray.can {
  server {
	idle-timeout = ${idle-timeout}
	request-timeout = ${request-timeout}
	request-chunk-aggregation-limit = 20m
	parsing {
	  max-content-length = 21m
	}
  }
  client {
	idle-timeout = ${idle-timeout}
	request-timeout = ${request-timeout}
	response-chunk-aggregation-limit = 20m
  }
}

Here is the code. That i' m doing:

test-akka

pathPrefix("complete") {
    post {
      entity(as[CompleteRequest]) { CompleteRequest => ctx =>
        val uNameAccountId = user.username.get + "|" + account.id.get
        (sActor ? JwtToken(uNameAccountId)).mapTo[Either[Rejection,String]].map {
          case Left(e) => ctx.reject(e)
          case Right(token) => {
            jwt_token = token
            var list2: Seq[String] = Seq()
            (sActor ? GetUserData(account, user)).mapTo[Either[Rejection, UserData]] map {
              case Left(userData) => Future.failed(new Exception())
              case Right(userData) => {
                .
				.
				.
                requestBody = JsonFormat.toJsonString(requestObj)
                (sActor ? CompleteReq(sessionId.substring(0, 31), jwt_token, requestBody)).mapTo[Either[Rejection, ByteString]] map {
                  case Left(error) => ctx.reject(error)
                  case Right(response) => ctx.complete(response)
				}
			  }
			}
		  }
		}
	  }
    }
}


case m: CompleteReq => {
val start1 = System.currentTimeMillis()
val actorSender = sender()
val result = completeService(m.session,m.jwttoken,m.completeRequest)
result.onComplete {
    case Success(response) => actorSender ! Right(response)
    case Failure(error) => actorSender ! Left(DarkroomVaErrorRejection(new Exception("not able to fetch data from DB",error),Some("not able to fetch data from DB")))
  }
}

def completeService(session: String, jwttoken: String, completeRequest: String): Future[HttpResponse] = {
	val pipeline: HttpRequest => Future[HttpResponse] = sendReceive ~> unmarshal[HttpResponse]
	val response: Future[HttpResponse] = pipeline(Post(remoteUrl, completeRequest)
	response
}

As shown in image last request is taking time to hit api(i.e. complete api). After complete api is hitted it gives response in millisecond. But somehow that last request is consuming time somewhere to hit api(i.e. "complete" api)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant