# Experiencing weird slowness when deployed

**URL:** <https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954>\
**Category:** Dash Python\
**Created:** [February 22, 2023, 7:16pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954 "2023-02-22T19:16:30Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 7:16pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/1 "2023-02-22T19:16:30Z")

</div>

This may not be anything anyone can help me with but I thought I’d ask anyways because I’m at a loss as for why.

When I work from home, I use a VPN with my company to be able to access their SQL databases and other things. My newest Dash app queries from them. When I’m in the office everything is totally fine and running fast and smoothly. When I’m home, it’s dreadfully slow. Even things that shouldn’t be slow.

An example of something that shouldn’t be slow is that I have 2 radio buttons and 5 drop downs. I have the placeholders in the dropdowns change based on the radio selection. When I change radio selections, it takes at least 30 seconds for the placeholder to change.

I’ve made previous dash apps in this same situation and never had slowness. The only difference is that in this dash app I’m serving the layout as a function. Could that be the problem? I don’t see why it would be but I didn’t do that in my other apps and haven’t had this issue.

Any thoughts would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [February 22, 2023, 7:21pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/2 "2023-02-22T19:21:40Z")

</div>

Hello @bpolasek,

How are you hosting the site? Locally at your house and then you are querying the data over the VPN?

If so, you have to keep in mind the round trip of the network for the SQL queries to perform. If, you were to host the app there at work and then access it while on the VPN, you may see a boost in speed.

---

<div class="post-metadata">

**Author:** ![jcuypers](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jcuypers](https://community.plotly.com/u/jcuypers)\
**Post date:** [February 22, 2023, 7:24pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/3 "2023-02-22T19:24:11Z")

</div>

Hi @bpolasek,

Can you see anything special in the network tab of the developer tools of your browser. Or can you see anything specific in the timings of your callback graph?

Reg,  
J.

---

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 7:35pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/4 "2023-02-22T19:35:34Z")

</div>

Here is a snippet of my network between selecting the final dropdown which triggers the graph and the graph and save buttons loading.

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/c/1/c1cb6d893b2f4c4cdd82aead90f9ead03a86cff5.png)

As you can see, it’s taking about 14 seconds for the graph to load (pretty quick in comparison to other trials). And this isn’t even running a sql query. All the sql queries have been run on page load and are sitting in dcc.Store components as dataframes.

---

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 7:36pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/5 "2023-02-22T19:36:24Z")

</div>

Yeah I’m not concerned with the SQL queries as I expect them to be slow on the VPN. But what’s weird to me is the changing of the callbacks that don’t involve SQL queries.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [February 22, 2023, 7:38pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/6 "2023-02-22T19:38:29Z")

</div>

We cant assume that your callbacks arent using queries… The data exchange shouldnt be using too much to transfer the little data that is taking place.

What is your callback structure?

What happens if you disconnect your VPN once your data is in the dcc.Store?

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [February 22, 2023, 7:41pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/7 "2023-02-22T19:41:44Z")

</div>

Are you using `localhost:port` / `127.0.0.1:port` for when you are accessing, or are you using your works IP address?

---

<div class="post-metadata">

**Author:** ![jcuypers](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jcuypers](https://community.plotly.com/u/jcuypers)\
**Post date:** [February 22, 2023, 7:43pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/8 "2023-02-22T19:43:10Z")

</div>

If you see in the network tab on a specific request, you can see the detail of where the time is spent. sometimes it can be just as stupid as a DNS request issue.

Also is the app/data hosted at your company or is it hosted in the cloud/or a third party

---

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 7:43pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/9 "2023-02-22T19:43:27Z")

</div>

Okay actually I left out a part that’s actually pretty important.

EDIT:

It’s not the VPN. We are hosting it on a virtual machine - NVIDIA DGX Server. So it has to run through there. Because when I run it NOT ON that server, with VPN, I don’t have these issues. Only when it’s deployed through that server AND on VPN do I experience the slowness.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [February 22, 2023, 7:46pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/10 "2023-02-22T19:46:16Z")

</div>

I am going to assume that you are using your dcc.Store in your callbacks as a State.

With that assumption in mind, it means that your data payload is always going to include that information, making it heavy. To avoid this, you can use ServerSide caching as provided by `dash-extensions`:

> [@Show and Tell - Server Side Caching](https://community.plotly.com/t/show-and-tell-server-side-caching/42854):
>
> The Store component in Dash makes it easy to [share state between callbacks](https://dash.plotly.com/dash-core-components/store). Under the hood, the data are stored as JSON in the browser. This approach is chosen to keep the server stateless (i guess), but it has a few drawbacks As the data are stored in JSON, you must convert objects from/to JSON in the beginning/end of each callback Since the callbacks are executed server side while the data are stored client side, the data will be sent across the wire every time a callback is invoked The maxi…

Or, you could pair down the info to be only what you need to drive your dropdown selections as well.

* * *

Or you could use clientside callbacks for pairing down the data of the selections, since I highly doubt that the round trip is necessary to filter down what selections you want to populate. XD

---

<div class="post-metadata">

**Author:** ![jcuypers](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@jcuypers](https://community.plotly.com/u/jcuypers)\
**Post date:** [February 22, 2023, 7:51pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/11 "2023-02-22T19:51:09Z")

</div>

I agree, but like 14s for 5 dropdowns and like a few Kb of data. this seems extreme. also on the 204 the same thing. seems to me there is something else wrong.

---

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 7:52pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/12 "2023-02-22T19:52:33Z")

</div>

Yeah the data pull itself is in total about 6k rows so I didn’t think it was that much. My other apps have handled more.

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [February 22, 2023, 7:54pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/13 "2023-02-22T19:54:01Z")

</div>

I’d ping your server on the VPN. See what your response time is without data.

---

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 7:54pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/14 "2023-02-22T19:54:45Z")

</div>

Would you say clientside is better than server-side caching? I was looking at server-side caching article before you updated your reply. If I were to go the server-side route, would DiskCacheManager work here instead of FileSystemCache?

```auto
cc = CallbackCache(cache=FileSystemCache(cache_dir="cache"))

```

Also for clarification the difference between:

```auto
@cc.cached_callback(Output("store", "data"), [Trigger("btn", "n_clicks")]) # Trigger is like Input, but excluded from args
def query_data():
    time.sleep(1) # sleep to emulate a database call / a long calculation
    return px.data.gapminder()

@cc.callback(Output("dd", "options"), [Input("store", "data")])
def update_dd(df):
    return [{"label": column, "value": column} for column in df["year"]]

```

The cc.cached\_callback and cc.callback is dependent on if the store is being used as output vs. input?

---

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 7:55pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/15 "2023-02-22T19:55:05Z")

</div>

Ping the sql server?

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [February 22, 2023, 7:55pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/16 "2023-02-22T19:55:47Z")

</div>

The server hosting your web app.

It should be the same as the IP address you are punching in to your url.

---

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 7:58pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/17 "2023-02-22T19:58:11Z")

</div>

Average 42 ms

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [February 22, 2023, 8:01pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/18 "2023-02-22T20:01:45Z")

</div>

Client side you wouldnt have to deal with the round trip at all, for things that dont require the server to manipulate, then it is quicker for sure.

42 ms shouldnt be bogging you down, but you might also be experiencing issues with bandwidth.

If you were to use ServerSide caching however, you’d see a boost on your initial loading of the page too.

---

<div class="post-metadata">

**Author:** ![bpolasek](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/bpolasek/32/22137_2.png) [@bpolasek](https://community.plotly.com/u/bpolasek)\
**Post date:** [February 22, 2023, 8:03pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/19 "2023-02-22T20:03:17Z")

</div>

Okay I’ll try client side first. Never worked with it so about to learn something new!

And I thought it could be my personal WiFi but I know others have had the same issues when they are at home. My boss just says it gives everyone a reason to come to the office 😂

---

<div class="post-metadata">

**Author:** ![jinnyzor](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jinnyzor/32/21194_2.png) [@jinnyzor](https://community.plotly.com/u/jinnyzor)\
**Post date:** [February 22, 2023, 8:05pm UTC](https://community.plotly.com/t/experiencing-weird-slowness-when-deployed/72954/20 "2023-02-22T20:05:32Z")

</div>

I have messed with VPNs and transferring files on a shared drive, it was a nightmare, even for people with fast networks.

I eventually had the files downloaded to a folder on their computer straight from the ip address where they were stored instead of the shared storage location.
